I have made these two classes in Java, and I need to define my structure like this:
class UnitType {
Position myPos;
public Position getPosition() {
return myPos;
}
}
class Unit extends UnitType {
Position myPos;
public Unit(Position myPos) {
this.myPos = myPos;
}
}
My question, can I do this following:
class UnitTest {
private Unit testUnit;
@Before
public void setUp() {
testUnit = new Unit(new Position(1,0));
}
@Test
public void testPositionUnit() {
assertEquals("Unit should be placed at (1,0)", new Position(1,0), testUnit.getPosition());
}
}
And if I can do this, what would happen if I updated the position in my Unit class. Will I be looking at a wrong pointer when calling getPosition()?
Many is wondering about my .equals method for my Position class so here it is: https://pastebin.com/Tfer1kqR
"this following"?