I understand that the topic with Cursor 's is "beaten", but I will still ask. Here is a classic query in the database.

  DatabaseHelper sqlHelper = new DatabaseHelper(context); SQLiteDatabase db = sqlHelper.getReadableDatabase(); Cursor cursor = db.rawQuery("select * from " + DatabaseHelper.TABLE_MAIN + " where " + DatabaseHelper.MAIN_MAX + " = " + max, null); 

Cursor is an Interface , there is no implementation in it directly in the methods, its (implementation) needs to be implemented by implementing the interface in some Классе . Cursor itself is extends Closeable , and SQLiteDatabase is extends SQLiteClosable , which in turn is implements Closeable . In Closeable only the close method.

In the example, we assign the result of the db.rawQuery(...) query to the Cursor link.

Interested in the following. What cursor.moveToFirst() Класс “hidden” behind the cursor reference, what does the methods cursor.moveToFirst() , cursor.moveToLast() , etc. implement directly? How can an Interface 's link manipulate data?

    1 answer 1

    Cursor is an interface, that is, a set of abstract methods that must be implemented by a particular class.

    In your case, this is a SQLiteCursor class, which extends AbstractWindowedCursor , which extends AbstractCursor , which implements CrossProcessCursor , which implements Cursor .

    If you want to rummage in guts as it is implemented - look here - these are the sources of SQLiteCursor

    • So the compiler runs through the classes implemented / affected by the Cursor / ohm, in this case in the reverse order in the specified chain and causes what is needed. An example of how the "tail (interface) is instructed by the dog (the class that implements it)", so to speak? - TimurVI
    • I do not advise you to try to penetrate into the methods of the compiler - you will finally carry out your brain. There are different ways of interfaces / classes - Barmaley