vendredi 30 janvier 2015

upcasting with reflection is not allowed

I have structure like this:



public interface InterfaceOne extends InterfaceTwo {}

public interface InterfaceTwo {}

public class ClassOne<T extends InterfaceOne> extends ClassTwo<T> {}

public class ClassTwo<InterfaceTwo> {}

public final class ClassThree extends ClassFour {

@Override
public final ClassOne<InterfaceOne> getObjectClassTwo() {
/*
* Multiple markers at this line
* - The return type is incompatible with com.example.ClassFour.getObjectClassTwo()
* - implements com.example.ClassFour.getObjectClassTwo
*/
return new ClassOne<InterfaceOne>();
}

}

public abstract class ClassFour {

public abstract ClassTwo<InterfaceTwo> getObjectClassTwo();

}


since ClassOne extends ClassTwo AND InterfaceOne extends InterfaceTwo why can I not say ClassOne<InterfaceOne> overrides ClassTwo<InterfaceTwo>? It would make perfect sense to me, but it is not allowed?


Also when I get rid of <> declaration i get yellow warning and everything works just fine. I would appreciate anyone explaining this to me. Thanks in advance:-)






Aucun commentaire:

Enregistrer un commentaire