• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling a method in a method?

 
Ranch Hand
Posts: 56
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic