@Documented @PolymorphicQualifier(value=UnknownUnits.class) @Retention(value=RUNTIME) @Target(value={TYPE_USE,TYPE_PARAMETER}) public @interface PolyUnit
Any method written using @PolyUnit conceptually has many versions: in each one, every instance of @PolyUnit has been replaced by a different unit qualifier such as @kg (kilograms) or @h (hours).
The following example shows how method triplePolyUnit
can be used to process either
meters or seconds:
@PolyUnit int triplePolyUnit(@PolyUnit int amount) { return 3*amount; } void testPolyUnit() { @m int m1 = 7 * UnitsTools.m; @m int m2 = triplePolyUnit(m1); @s int sec1 = 7 * UnitsTools.s; @s int sec2 = triplePolyUnit(sec1); //:: error: (assignment.type.incompatible) @s int sec3 = triplePolyUnit(m1); }