I’m trying to write the framework for a robot path planner, and I have an abstract class called Plan
which contains some Movement
s and a MovementType
enum value:
public abstract class Plan<T extends RobotState> {
protected MovementType movementType;
...
/**
* Creates a new Plan object with the given Movements.
* @param movements
*/
public Plan(Movement... movements) {
this.movementType = ... // I need to get the MovementType from T
this.movements = movements;
}
...
}
where the RobotState
class is extended by TranslationState
and RotationState
. I’m looking to store a MovementType
enum value in these subclasses in a way that I can get it directly from T
in the first line of the constructor (line 9). This is an ExamplePlan
class that inherits from Plan<TranslationState>
:
public class ExamplePlan extends Plan<TranslationState> {
// when this gets constructed, movementType should equal MovementType.TRANSLATION
}
I know that abstract static MovementType getMovementType()
can’t be declared in RobotState
because it’s static, and I don’t really want to pass a MovementType
through the Plan
constructor parameters because it feels redundant; there are plenty of other generic classes in the framework that depend on the MovementType
of a RobotState
and I don’t wan’t MovementTypes cluttering all the code.
Is there a standard way I should be doing this, or is this not possible and do I have to use a workaround? Thanks.
stephen cai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.