Could someone explain how Java is able to pass an arg to a class's constructor then assign a value returned from that class's get-method() before an object of that type has been created. Example: int someVar = new SomeClass( argToConstructor ).aGetter() ; What/where is the obj for SomeClass? I understand the following, but not the above. SomeClass anObj = new SomeClass( argToConstructor ) ; int someVar = anObj.aGetter() ;
The cool thing about Java (and when I think of it, a lot of languages), is that you can 'cascade' your calls.
Think of it this way...
the following code returns a certain kind of object. In one example, you have an explicity declared object reference (a variable) that can receive that new object (ie: an assignment happens.) But in another case, you may simply say "well just 'hold' it for me, I don't really need that intermediate object, because what I'm really after is something else". And this is what happens when you cascade with the 'dot' syntax.
You do it all the time with System.out.println I haven't compiled it so don't take my word on it, but I think you get the idea. [This message has been edited by Mike Curwen (edited May 23, 2001).]
Joined: Mar 01, 2001
I understand now. Thanks Mike, you made the explanation simple to understand.