public class Number { public double val; public Number(double d) { val = d; } public Object op-(double d, Object c) { assert this == c; return new Number(d - val); } public double op-=(double d, Object c) { assert this == c; return d - val; } public Object op-(double d) { return new Number(val - d); } public Object op-=(double d) { return new Number(val - d); } public String toString() { return ""+val; } public static void main(String[]args) { Number n1 = new Number(1.0); Number n2 = new dNumber(2.0); System.out.println(10 - n1); System.out.println(9.0 - n1); System.out.println(8.0f - n1); System.out.println(7L - n1); System.out.println(n1.op-(6L,n1)); System.out.println(n1 - 0.5); System.out.println(n1 - 2); System.out.println(8.0f - n2); System.out.println(7 - n2); System.out.println(n2 - 2.5); System.out.println(n2 - 10); double d = 10.0; double e; d -= n1; System.out.println(d); System.out.println(d -= n1); System.out.println(d -= n1); System.out.println(e = (d -= n1)); System.out.println(e); System.out.println(d -= n1); System.out.println("d="+d); System.out.println(n1); System.out.println(n1 -= d); System.out.println(n1 -= d); System.out.println(n2); System.out.println(n2 -= d); dNumber dn2 = new dNumber(n2.val); dn2 = broadcast dn2 from 0; // workaround for PR630 try { dn2 -= 4; System.out.println(dn2+"error!"); } catch (ClassCastException exn) { System.out.println("done."); } } } public class dNumber extends Number { public dNumber(double val) { super(val); } public Object op-(double d, Object c) { assert this == c; System.out.println("hi"); return new Number(d - val); } public Object op-(double d) { System.out.println("there"); return new Number(val - d); } }