C # syntax syntax in Java

I read questions / answers saying that Java does not and cannot get C # style properties. However, in this question: How to organize a database access code in an Android project? , there is an answer with some sample code, for example:

c = localDBRW.rawQuery(sql, selectionArgs);

In the comments on this answer, he says that localDBRW is "defined as a reference to getWritableDatabase ()". For me, this means that in the line above getWritableDatabase () is called and rawQuery is called as a result of getWritableDatabase ().

So my question is: how is this done?

In C #, that would be trivial. I'm new to Java, so I'm not even sure what the terminology is that will lead me to the answer. Searches for “properties,” “methods,” and “references” did not result in this particular use.

Summary of responses:

I grabbed for a dream. I interpreted the original expression so that my wishes could come true. Alas, this is not the way things are. Java has no hope for the syntax of C # properties, and I was sent to the eternity of writing obj.getX () instead of obj.X.

+1
source share
3 answers

localDBRW"defined as a reference to getWritableDatabase()"

I believe that this simply means that it was before the application, and nothing more:

localDBRW = getWritableDatabase();

Java . , , . , , , .

+1

localDBRW - getWritableDatabase(). getWritableDatabase(). localDBRW getWritableDatabase(), .

. localDBRW (-) getWritableDatabase(). , . Java ( ).

+1

. , - .

Java API- , . ,

 theMethod.invoke()

 // assuming you have a Class clazz and Object clazzObj
 Method theMethod= clazz .getMethod(
          "someName", null /* or a list of desired params*/);

 theMethod.invoke(clazzObj, arglist);

, (, wrpaping {clazzObj, theMethod} , , , - .

=== ====

, SQL , .

, JDBC, . .

I see no difference between Java and C # approaches. The example you are referring to has

c.moveToFirst();
recordID = c.getString(c.getColumnIndex("id"));
c.close();

A JDBC tutorial shows code like this

String query = "
SELECT COFFEES.COF_NAME " +
   "FROM COFFEES, SUPPLIERS " +
   "WHERE SUPPLIERS.SUP_NAME LIKE 'Acme, Inc.' " +
   "and SUPPLIERS.SUP_ID = COFFEES.SUP_ID";

ResultSet rs = stmt.executeQuery(query);
System.out.println("Coffees bought from Acme, Inc.: ");
while (rs.next()) {
    String coffeeName = rs.getString("COF_NAME");
    System.out.println("     " + coffeeName);
}

where do you get coumns by name.

+1
source

Source: https://habr.com/ru/post/1745807/


All Articles