I have a generic class:
public abstract class Container<T> {
...
protected T value;
private SomeType type;
public T add(T toAdd);
public Container(T value, SomeType type) {
...
}
...
}
and a MathHelper-Class:
public class ContainerMathHelper {
private ContainerMathHelper() {}
public static Container<?> add(Container<?> a, Container<?> b) {
check for same container-type as types are unique -> same impl of container
???
return addT(casted_a, casted_b);
}
public static <T> Container<T> addT(Container<T> a, Container<T> b) {
return a.add(b);
}
}
now I don't know how to properly cast both a(Container<?>
) and b(Container<?>
) to the same type to use the addT function.
I already tried things like casting them both by using
clazzX.cast(a) and clazzX.cast(b) with clazzX being the same object
and some other things.
Does anybody know a solution?