B
Benjamin Lerman
Hi all,
I encounter a strange behavior with generics that I do not understand.
I have the following interfaces:
public interface Int1<E> {
}
and
public interface Int2<E> extends Int1<Integer> {
}
and I have somewhere the following lines:
void foo(Int2 o) {
Int1<Integer> p = o;
}
The java compiler gives the following warning:
Type safety: The expression of type Int2 needs unchecked conversion to
conform to Int1<Integer>
I do not understand why this warning exists. Moreover it prevents the
compiler to understand that an Int2<E> is also an Int1<Integer>, so it
prevents a lot of type checking.
Is there any solution ?
Thanks.
Benjamin Lerman
I encounter a strange behavior with generics that I do not understand.
I have the following interfaces:
public interface Int1<E> {
}
and
public interface Int2<E> extends Int1<Integer> {
}
and I have somewhere the following lines:
void foo(Int2 o) {
Int1<Integer> p = o;
}
The java compiler gives the following warning:
Type safety: The expression of type Int2 needs unchecked conversion to
conform to Int1<Integer>
I do not understand why this warning exists. Moreover it prevents the
compiler to understand that an Int2<E> is also an Int1<Integer>, so it
prevents a lot of type checking.
Is there any solution ?
Thanks.
Benjamin Lerman