This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics question

 
Rikesh Desai
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()??
 
Maren Fisher
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic