I have the following entities in my domain model:
class Point {
public String details;
public Point() {
details = "empty";
}
public Point(String details) {
this.details = details;
}
}
class BasicPoint<X, Y> extends Point {
public X x;
public Y y;
public BasicPoint() {}
public BasicPoint(X x, Y y) {
this.x = x;
this.y = y;
}
}
class Collector<T> {
T elem;
public void collect(T elem) {
this.elem = elem;
}
}
I want to apply operations on data and return that data as Point or BasicPoint, as declared above, but the compiler is complaining with the following error although OUT extends Point:
class Operator<OUT extends Point> {
public Collector<OUT> operate(Collector<OUT> collector) {
// compile error, collect(OUT) cannot be applied to BasicPoint<Integer, Integer>
collector.collect(new BasicPoint<Integer, Integer>(1,2));
return collector;
}
}
Main method should look like:
Collector<BasicPoint<Integer, Integer>> c = new Collector<>();
c = new Operator<BasicPoint<Integer, Integer>>().operate(c);
System.out.println(c.elem.getClass() == new BasicPoint<Integer, Integer>().getClass());