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 Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics" Watch "Generics" New topic
Author

Generics

Chhabra Ram
Greenhorn

Joined: Sep 22, 2007
Posts: 2
Hi,



In the above code i am getting compile time error at line 1, line 2, line 3.....

IN the method argument i am saying that accept anything that extends Number..... so line 1 and line 2 should not give error..... can you please explain me the reason why it is behaving like that?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Does Object extend Number?? The answer is no so line 1 should give error. Now do you know exactly that type would be given to you at runtime? What if I pass the method Parent<Float>. Should I be allowed to set its data to Number or Integer?? It would be easier to understand if you think of a Collection instead of a custom class. Also you've not shown the code of Parent class so I'm assuming that it looks something like this


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Generics
 
Similar Threads
Generic Question: wildcard with super
Generics (again)
Generic Problem
What's the reason ?
Regarding Generics wildcards