Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about generics and collections

 
Santhi Bharath
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my code



i can't understand why it compiling successfully!! how compiler knows the toString() method is there or not as the toString() not there in java.lang.Number class .any body can please explain.thanks in advance
 
ramesh maredu
Ranch Hand
Posts: 210
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


when you instantiate generic class with out using any generic types. it takes Object as generic type.

In above code N is considered as Number because N extends Number.
Number class has toString() method inherited from Object
[ September 30, 2008: Message edited by: ramesh maredu ]
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.Number extends java.lang.Object

and Object class has toString() method.
 
Santhi Bharath
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you guys i got it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic