在类中乘以/加/除/减去值

时间:2014-06-21 19:46:34

标签: java math

我有这个非常简单的类,如下所示:

public class Vector2{

    public final double x;
    public final double y;

    public Vector2(final double x, final double y){
        this.x = x;
        this.y = y;
    }
}

我有可能在Java中做这样的事吗?

Vector2 amount = new Vector2(10, 40) * 2;

System.out.println(amount.x);  // Prints 20
System.out.println(amount.y);  // Prints 80

0 个答案:

没有答案