Unexpected generics behaviour
Posted
by pronicles
on Stack Overflow
See other posts from Stack Overflow
or by pronicles
Published on 2010-03-15T06:50:02Z
Indexed on
2010/03/15
6:59 UTC
Read the original article
Hit count: 340
I found strange generics behaviour. In two words - thing I realy want is to use ComplexObject1 in most general way, and the thing I realy missed is why defined generic type(... extends BuisnessObject) is lost. The discuss thread is also awailable in my blog http://pronicles.blogspot.com/2010/03/unexpected-generics-behaviour.html.
public class Test {
public interface EntityObject {}
public interface SomeInterface {}
public class BasicEntity implements EntityObject {}
public interface BuisnessObject<E extends EntityObject> {
E getEntity();
}
public interface ComplexObject1<V extends SomeInterface> extends BusinessObject<BasicEntity> {}
public interface ComplexObject2 extends BuisnessObject<BasicEntity> {}
public void test(){
ComplexObject1 complexObject1 = null;
ComplexObject2 complexObject2 = null;
EntityObject entityObject1 = complexObject1.getEntity();
//BasicEntity entityObject1 = complexObject1.getEntity(); wtf incompatible types!!!!
BasicEntity basicEntity = complexObject2.getEntity();
}
}
© Stack Overflow or respective owner