This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Generics assignment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Generics assignment" Watch "Generics assignment" New topic

Generics assignment

Anup Om
Ranch Hand

Joined: Dec 30, 2009
Posts: 62

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

Joined: Oct 01, 2001
Posts: 2853

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

Joined: Oct 27, 2005
Posts: 19697

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.

How To Ask Questions How To Answer Questions
wood burning stoves
subject: Generics assignment