0

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?*);
}
Free Bullets
  • 127
  • 1
  • 1
  • 6
  • 1
    Your question isn't clear. Method `angle` is in class `MyScannedRobotEvent`, so you can't invoke it from `MyRobot` the way you have it coded. Please describe more clearly with a compilable example what you are trying to accomplish. – Jim Garrison Dec 24 '10 at 02:52

1 Answers1

1

Pass this.

int a = MyScannedRobotEvent.angle(this);

See also:

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Ah thanks. I'm trying out Java after learning C#/VB .NET. Is this the best way of doing it? – Free Bullets Dec 24 '10 at 02:56
  • Depends on the context, which isn't clear from your question. You'll discover it sooner or later though. As far now, that's the only way. – BalusC Dec 24 '10 at 03:19
  • @Free Bullets: Buddy you should read and practice a lot to be comfortable with Java and to know the best ways. – Mudassir Dec 24 '10 at 03:34