The classes I am dealing with are as follows,
public interface One{
public Two get();
}
public class Foo{...}
public class Bar extends Foo{...}
public abstract class Parent<T extends Foo> implements One {...}
public abstract class Child<T extends Foo> extends Parent<T>
I have a static method that will return a Child object given a Foo object,
public static Child<? extends Foo> get(Foo f){...}
This method returns a child constructed from either a Foo or Bar object. The code that throws the error is this,
Foo f = new Foo();
Child<? extends Foo> child = O.get(f);
Two t = S.apply(child);
The apply method,
public Two apply(One o){...};
The error that gets thrown is,
apply(One) in S cannot be applied to (Child<capture#123 of ?>)
My current workaround for this problem is to change the code to this,
Foo f = new Foo();
Child<? extends Foo> child = O.get(f);
Object o = child;
One one = (One)o;
Two t = S.apply(one);
This resolves the error, I have no idea why the explicit cast to object needs to be there, but there it is.
Can anyone tell me if it is possible to modify the code so the casts are not necessary to get this to work?