using keyword brings the defined class into the context.
Another example with multiple static extensions:
A few things to note:
- If the same method is defined in multiple static extension classes,
usingexpressions are checked from bottom to top. For example if the method
lastis also defined in
ArrayUtils2then it will take precedence as
ArrayUtils2is the bottom class in the above example.
- Built in class fields would take priority over the static extension fields. For example if you define
ArrayUtilsclass above it wouldn’t work as
toStringis a built in array method and it takes precedence.
- Compiler metadata
@:noUsingcan be used in static extension class if you want to omit any field being included in the context. Check the example below.
You can’t use the method
second as the compiler will not include it in the context when used.