This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on generics - from Niko questions  RSS feed

 
Anuradha Prasanna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When i try to compile the above code, it fails.
say(Set<Double> set) and say(Set<Boolean> set) is not a valid overload??
can any one explain why?

also,

can anyone explain, why the instanceof examples below give compiler error???

a)

b)
 
Ankit Garg
Sheriff
Posts: 9608
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you might know, generics is only for compile time type safety. The JVM doesn't know about generics. So if you create a List<String>, to the JVM its the same as List without any types. That's why when you write two methods like
Here after type erasure both the methods will have the same signature, so there is no overloading and thus you get an error. You can find more details about overloading here and about instanceof here...
 
Anuradha Prasanna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Ankit, i will look into it..
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!