Search code examples
javaclassinheritancerobocode

Class Self-Reference


I have the following code. The angle function needs some information from the class it was called from. What's the best way to do this?

class MyScannedRobotEvent extends robocode.ScannedRobotEvent {

    public int angle(robocode.Robot myRobot) {
        return (int) Math.toRadians((myRobot.getHeading() + getBearing()) % 360);
    }
}

public class MyRobot extends robocode.Robot {
int a = MyScannedRobotEvent.angle(*WHATDOIPUTHERE?*);
}

Solution

  • Pass this.

    int a = MyScannedRobotEvent.angle(this);
    

    See also: