Class Self-Reference

Free Bullets picture Free Bullets · Dec 24, 2010 · Viewed 8.9k times · Source

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?*);
}

Answer

BalusC picture BalusC · Dec 24, 2010

Pass this.

int a = MyScannedRobotEvent.angle(this);

See also: