• 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

basic question about method calls

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why we make obj.getClass().getName() call? I understand that this will return the name of the class, but my question is why is the syntex the way it is, i mean getClass method calls getName method.
where this type of call is used ?
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have an object and do a getClass() on it, it will return another object of the Class class. If you look in the API for Class you will see that it has a method getName() that returns a String representation of the class.
you COULD have split that syntax up into 2 statements:
Class c = obj.getClass();
String s = c.getName();
But it is more streamlined to weld it all together.
String s = obj.getClass().getName();
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at how JavaBeans work. All properties are encapsulated in getXX and setXX methods. Whenever you see a getSomething() method, you know it will simply give you the Something property on the object. Any calls from there, eg xx.getSomething().runAway("fast"); are methods on the object that getSomething() gave you.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic