Sto lavorando su un progetto che ha un oggetto chiamato Vector2Java supporta l'overloading dell'operatore?
public static class Vector2 {
public Vector2 (float x, float y) {
this.x = x;
this.y = y;
}
public float x;
public float y;
public static Vector2 ZERO = new Vector2 (0, 0);
public static Vector2 FORWARD = new Vector2 (0, 1);
public static Vector2 LEFT = new Vector2 (1, 0);
public static float Distance (Vector2 a, Vector2 b) {
return (float) Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
}
}
e vorrebbe effettuare le seguenti operazioni:
Vector2 a = new Vector2 (2.32, 453.12);
Vector2 b = new Vector2 (35.32, 532.32);
Vector2 c = a * b;
// c.x = 2.32*35.32
// c.y = 453.12*532.32
float num = 5;
c = a * num;
// c.x = 2.32*5
// c.y = 453.12*5
è possibile? In tal caso, come posso farlo e come si chiama? Grazie in anticipo.