9.5. Augmentations Resolution Order

The augmentations resolution order is as follows:

  1. native java method (i.e. an augmentation can’t override a native java method),
  2. locally applied augmentations:

    1. simple augmentations: augment MyType { ... },
    2. named augmentations: augmentation Foo = { ... } and augment MyType with Foo in the current module. Multiple applications are searched in the application order,
    3. externally defined named augmentations with fully qualified name: augmentation Foo = { ... } in module Augmentations, and augment MyType with Augmentations.Foo in the current module,
    4. named augmentation defined in an imported module: augmentation Foo = { ... } in module Augmentations, and augment MyType with Foo in the current module that import Augmentations (imported module are searched in the importation order),
  3. augmentations applied in imported modules: using the same order than locally applied ones, in the importation order.

The first matching method found is used. It is thus possible to “override” an augmentation with a more higher priority one (in the sens of the previous order).

Tip

Since importing a module imports all the applied augmentations, and given the somewhat complex resolution order when involving simple and named augmentations, being local, external or imported, and involving class hierarchies, knowing which method will be applied on a given type can be difficult. A good modularisation and a careful application are recommended.