| Author |
Question on generics - from Niko questions
|
Anuradha Prasanna
Ranch Hand
Joined: Mar 09, 2006
Posts: 115
|
|
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)
|
SCJP 6.0 90%
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
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...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Anuradha Prasanna
Ranch Hand
Joined: Mar 09, 2006
Posts: 115
|
|
|
thanks Ankit, i will look into it..
|
 |
 |
|
|
subject: Question on generics - from Niko questions
|
|
|