Annotation Type PolyUnit


A polymorphic qualifier for the units-of-measure type system implemented by the Units Checker.

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)
  @s int sec3 = triplePolyUnit(m1);
 }