• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling a method in a method?  RSS feed

 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to get my head around Multi threading when I found this line in an example in my book:

Thread.currentThread().getName();

how come? I'm familiar with something of this form
Object.method();
or
class.staticmethod();

but the line of code above just confuses me o_O
 
salvin francis
Bartender
Posts: 1612
36
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me give you an example...



What do you think happens in the above code ?
 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:Let me give you an example...
. . .
What do you think happens in the above code ?


Ohhhh! It clicks!
I get it new, it would print out "Growl !!"
so saySomething() is calling the is called in the tiger object returned by getTiger()

Dude you're awesome! Thank you!
 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:

AA: I have removed part of the quote; there is usually no need to quote the whole of a preceding post.



Alright 👍
 
salvin francis
Bartender
Posts: 1612
36
Eclipse IDE Google Web Toolkit Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

Now for next assignment


 
Ahmad Auada
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:Thanks

Now for next assignment




soo basically a chain of methods that pass the tiger object to each other and each method modifies a variable.

so it will say Growl!! My name is Timmy, I am a white color tiger. Today am feeling angry.

Cool technique! I like it!
 
salvin francis
Bartender
Posts: 1612
36
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahmad Auada wrote:
soo basically a chain of methods ...


Very true, its called method chaining https://en.wikipedia.org/wiki/Method_chaining
 
Campbell Ritchie
Marshal
Posts: 55768
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You write several methods in a chain but you do not call the methods on one another.
The first thing you write is an object reference. Then you call its method and that returns another object reference. In the latter case you get several references to the same object; in the earlier example with the Cage you had references to different objects to call methods on.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!