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 Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics assignment

 
Anup Om
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why can't I do the assignment at Line 1? a, which is of type <T extends A> can't be assigned to a variable of type A. why?

Thanks in advance for help.

EDIT After seeing Greg's reply: I added definition of class A.
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little confused by your use of generics with a static, but I think the issue is you need to tell it what A is. So if you changed it to:



then it should work.
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try that code the assignment works just fine. The return is the only line that fails to compile, and that's logical. T can be a subclass of A, it does not need to be A itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic