Re: Hairy generics question
On 02/21/2012 11:05 AM, Roedy Green wrote:
On Tue, 21 Feb 2012 06:30:51 -0800 (PST), sclaflin
<steve@steveclaflin.com> wrote, quoted or indirectly quoted someone
who said :
Why can I use a class that extends CompItemView for the V type, and
not CompItemView itself?
Possibly because it thinks you are trying to implement multiple
abstract classes not Interfaces. Generics don't use the term
"extends" consistently which sows confusion. I did not follow your
details. I am just throwing that out.
Red herring. The OP used the keyword 'extends' in syntactically correct
fashion. There is no implication of "trying to implement multiple abstract
classes", not least because the OP has not averred such a compilation failure
but one of failure to match bounded parameters.
Remember that the compiler - nor, indeed, the programmer - can know which
binding of the parameter applies. Thus when there are no type assertions tying
the generics parameters together, you have a "bound parameter" mismatch. You
cannot assert the types are the same.
Plus, the OP tried to use 'CompItemView', a raw type!, where the assertion
asked for a generics parameter. NEVER USE THE RAW TYPE OF A GENERIC!
It just doesn't extend the same generics parameters as the target declaration.
The OP is trying to shoehorn a type into the 'V' parameter that doesn't meet
the declared restrictions:
'CompItemView<AInfo, CompA, CompItemView<AInfo, CompA, CompItemView>>'
The OP's type assertions are tangled, inconsistent and incorrect. This is
normal when sussing out type assertions. Type reasoning isn't easy. One way to
ameliorate that is to keep your assertions simple to start with. Avoid
circularity except where it makes sense (as in
public abstract class Enum<E extends Enum<E>>
implements Comparable<E>, Serializable
and
public enum TimeUnit extends Enum<TimeUnit>
).
In the OP's case we have generics parameter triplets, where the triplet
elements themselves depend on the same triplet parameters, with random
'extends' clauses tossed in. I'm curious as to the OP's intended type
assertions here - if they share that we can help translate them into generics.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg