I have the following defined interface which is intended to be implemented by all the implementations of a 3d vector:
public interface IVector3<T extends Number> extends IVector<T> {
// Other stuff
public static <T extends Number, V extends IVector3<T>> V cross(V target, IVector3<?> vector0, IVector3<?> vector1) {
// Implementation
}
public static <T extends Number, V extends IVector3<T>> V cross(Supplier<V> factory, IVector3<?> vector0, IVector3<?> vector1) {
return cross(factory.get(), vector0, vector1);
}
}
I've also defined the follow implementation of the interface:
public class Vector3f extends Vectorf implements IVector3<Float> {
// Other stuff
public static Vector3f cross(IVector3<?> vector0, IVector3<?> vector1) {
// The annoying required cast
return IVector3.cross((Supplier<Vector3f>) Vector3f::new, vector0, vector1);
}
}
So, why does java requires me to make that cast of the reference constructor otherwise it claims the call to the method to be ambiguous?
Shouldn't the bounded type parameter solve the ambiguity?
And finally, is there any solution to avoid having to cast the reference constructor without changing the bounded type parameters?
Note: No other class/interface in the hierarchy defines a method (static or not) named "cross".
Note 2: I'm using Java 12.