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 question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Generics question" Watch "Generics question" New topic
Author

Generics question

Rikesh Desai
Ranch Hand

Joined: Jun 02, 2010
Posts: 83
Source : ExamLab



At line 1, why is new E() not possible??
As from line 2,
? super T --> E super T which implies T extends E
T extends E from --> public <T extends E>...

everything matches, then why is new A(); only possible and not new E()??


OCPJP 95%
Maren Fisher
Greenhorn

Joined: Nov 29, 2009
Posts: 7
You cannot do "new E()" because E is just a placeholder for a type that will be defined when you instantiate the class. The compiler does not know what type E represents.

You can do new A because A is a concrete class. But for E all you know is it is a type that extends A, but you don't know what that type that is. Hence you cannot do new E();
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Generics question
 
Similar Threads
Self Written Code on Generic Problem
Generics - return types
Generic question from Master Exam
Generics question from Exam Lab