I have the following classes and interfaces:
public interface Curve<T extends Path<Vector2>> {
List<T> splines();
}
public final class CachedCurve implements Curve<Path<Vector2>> {
public CachedCurve(final Curve<Path<Vector2>> source) {
// ...
}
@Override
public List<Path<Vector2>> splines() {
// ...
}
}
public class BezierCurve implements Curve<Bezier<Vector2>> {
public BezierCurve(List<Vector2> sample, float tresholdPerpDistance) {
// ...
}
@Override
public List<Bezier<Vector2>> splines() {
// ...
}
}
I use the above like so:
Curve<Path<Vector2>> curve = null;
curve = new BezierCurve(new LinkedList<Vector2>(), 10f); // Compilation error
curve = new CachedCurve(curve);
I can't seem to fix this compilation error:
Type mismatch: cannot convert from BezierCurve to Curve<Path<Vector2>>
Maybe it's unclear what I'm trying to do from the (apparently incorrect) code.
I would like to have one generic interface Curve
. Then I want to have one class that can cache any Curve
and one that is a special implementation of the Curve
with Bezier splines. I wish to code this generically so that I can write:
Curve<Path<Vector2>> curve = null;
curve = new BezierCurve(/* */);
curve = new CachedCurve(curve);
Relevant classes from libGDX
: