Simon schreef:
> Hi,
>
[quoted text clipped - 16 lines]
>> Type safety: The expression of type Int2 needs unchecked conversion to
>> conform to Int1<Integer>
Indeed, for the same reason why you get this warning when you use List
foo = new ArrayList<Date>(); : you use an ungeneric instance of a
generic class.
> I'm not sure why you get that warning, but you can avoid it if you declare foo
> like this:
>
> void foo(Int2<Object> o)
Well, I would declare foo like something more meaningful than
Int2<Object>, but that entirely depends on what you meant the second
generic parameter of Int2 to mean.
> You can reproduce the same warning with the following simpler code that doesn't
> use inheritance:
[quoted text clipped - 5 lines]
> example where this is significant or rather where using Int1 instead of
> Int1<Object> causes any problems/exceptions?
There is a huge difference between Collection<Object> and just
Collection. For example Collection<Integer> is an heir of Collection,
but not of Collection<Object>. (Interestingly, in Eiffel this is not
the case. I wonder how they handle the problems that arise out of this.
They had generics from the start, so the whole type erasure stuff does
not exist.)
H.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html