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.
Java has "type erasure", which means that generic information doesn't exist at runtime. It's only used by the compiler. So the following signatures:
both compile to the signature:
which means you get a conflict.
Bruno Sant Ana
Joined: May 17, 2012
OK, but I'm not trying to use both at the same time like this:
Well, both "T" and "U" can be String objects (or can be Object objects -- the super of String). Question: assuming that they are *not* string objects, then how should the compiler perform the "t+u" operation?
Bruno Sant Ana wrote:OK, but I'm not trying to use both at the same time...
Ah, sorry, I misunderstood.
The reason you get an error (and I get a different error to the one you reported) is that super isn't allowed as a bound on a type variable. You can have lower bounds on wildcard type arguments, but not where you've used them.
Unlike ordinary type variables declared in a method signature, no type inference is required when using a wildcard. Consequently, it is permissible to declare lower bounds on a wildcard, using the following syntax, where B is a lower bound: