File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  17

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