It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on generics - from Niko questions Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Question on generics - from Niko questions" Watch "Question on generics - from Niko questions" New topic
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
    
    2

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..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on generics - from Niko questions
 
Similar Threads
Method Overloading question
Generics :Apart from "null" no input to a method is compilable
Overriding generic methods
Wildcards in Class declaration
Doubts about Generics