I have defined a class called “Entity” with a Point2D object in it called “pos”. The class is a superclass and it’s not specified if “pos” should be a Point2D.Float or a Point2D.Double, that’s left for the inheritors to decide. The problem is I don’t know how to override this object to make it a Point2D.Float (for example) without getting an error.
import java.awt.geom.Point2D;
public class Entity {
Point2D pos;
public Entity(Point2D pos) {
this.pos = pos;
//...
}
//...
}
import java.awt.geom.Point2D;
public class Enemy {
// Somehow overrite "pos" so it must be Point2D.Float within this subclass
public Enemy(Point2D.Float pos) {
this.pos = pos;
//...
}
//...
}
I tried to simply insert the @Override
annotation before declaring Point2D.Float pos;
, but the virtual environment I was working on indicated that that was an illegal use of @Override
.
I wasn’t sure what I was supposed to do and I didn’t find any answers on Stack Overflow.
Thank you in advance.
Gabriel Vinagre Coppens is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.