I am having a heck of a timer understanding certain syntax in Java (and Visual basic for applications) that uses the member access or "dot" operator.
Would some please explain to me exactly what the following statements mean:
whateverVar = myObject.someMethod().someOthermethod(); (Seen in Java)
SomethingOrOther.someMethod().someField.SomeotherField (seen in Visual Bsic for applications)
I know this is a Java forum and I do not intend to offend anyone, however, to some degree the use of the member access operator or "dot" operator may be the same in both languages. I am trying to understand what exactly these statements mean.
I tried to write a java application to test the syntax by creating a test class with multiple methods but couldn't get it to work. The only thing I can think of is that the multiple dot operator mean to access a derived class method and then a base class method.
In java (I don't know about visual basic) Objects as well as methods can be members of a class. To access a member of class we can use dot operator on a object of that class.
The dot operator has associativity from left to right. so if a method returns some object then we can use dot operator on method call to access members of returned object.
For example suppose we have 3 classes:
using dot operator we can write:
We can rewrite the above line as:
this will give: (objB.getC()).printHi();
this will give: (an object of C).printHi();
this will call printHi(); defined in class C
Thanks very much, I really appreciate your reply. It is very informative and organized very well. When domeone can explain something the way that you did, it shows that they understand the concept fully.
I asked this question of my C++ and Java instructors but they couldn't explain the concept in terms one could understand-at least me.
Joined: Jun 19, 2011
Seetharaman Venkatasamy, Unnar Björnsson, and Nico Van Belle
Thank you also! I really appreciate your replies!
I am very glad I joined.