Scala compiler turns value classes into their unboxed type, which eliminates their cost for runtime. Inspecting the compiled class file for Angle
, you'll see:
public static double Zero();
So from Java's point of view, Angle.Zero returns a double; it's not aware of the semantics of Scala's value classes.
Angle's own methods, such as degrees
, get compiled into a) a static extension method that takes in the unboxed value (double
) b) an instance method:
public static double degrees$extension(double);
public double degrees();
Which means the latter can still be called on an instance of Angle
in Java:
Angle a = new Angle(0);
Assert.assertEquals(a.degrees(), 0, 1E-9);