This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String vs Object

 
mvPrasad Regula
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is the code below printing String version, as both String and Object accept null value.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"myPrasad Regula", please check your private messages for an important administrative matter or your account will be removed.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I able to reply....
Check the code below......



The method, which has the lower place in the hierarchy will be invoked..... In this example, Class C is the lowest class in the hierarchy. So the method with that type of parameter will be invoked. Same for your coding, as String is a sub class of Object.......
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Abimaran Kugathasan is right. Always more specific version of method is called and because whenever you are coming down in a hierarchy you a more specific about the class. So always the method with argument of lowest level of the hierarchy is called.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Muhammad Khojaye
Ranch Hand
Posts: 449
IntelliJ IDE Java Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See also this FAQ
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic