Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

meaning of "return this"

I have been following android tutorial on the internet about SQLite. I got a statement which I'm not sure about:

public HotOrNot open(){
    ourHelper = new DbHelper(ourContext);
    ourDatabase = ourHelper.getWritableDatabase();
    return this;  
}

What does return this mean in this method ? is it the current object or context ? thanks

like image 617
Dodi Avatar asked Jun 19 '13 10:06

Dodi


Video Answer


1 Answers

return this returns the current object instance. I don't know what HotOrNot class is, but it's clear that this method is defined in that class. In the method, member variable ourHelper is initialised with a new database helper and member variable ourDatabase is assigned a writable database object from that helper - after which the instance of the class is returned - most likely, so that the calls could be chained, e.g.

new HotOrNot(myContext).open().runQuery("some query text")

See the Java language specifications for more information on this keyword.

like image 119
Aleks G Avatar answered Sep 28 '22 13:09

Aleks G