user2089523
user2089523

Reputation: 63

How do I create an object referencing an instantiated class object inside a method that didn't pass the object as an argument?

synchronized void drop(Board board) {
    int[][] a = getArray();
    int[][] b = board.getArray();

    //I don't have currentObject here... what do I need to write?                
    if (Board.goDown(currentX, currentY, b, a, board, currentObject)) {
        currentY++;
        updateXY();
    }
}

The method call is currentObject.drop(board), but we can't pass in currentObject as a variable.

Is there any easy way of doing this or I just have to rewrite the entire code?

Upvotes: 0

Views: 71

Answers (1)

Iswanto San
Iswanto San

Reputation: 18569

You can use this keyword.

"this" is a reference to the current object.

Upvotes: 2

Related Questions