Parametrized properties
Another neat feature, is the possibility to provide parameters on method
interfaces.
The property values shall respect the positional notation specified by the
java.util.Formatter
class:
public interface Sample extends Config {
@DefaultValue("Hello Mr. %s!")
String helloMr(String name);
}
Sample cfg = ConfigFactory.create(Sample.class);
print(cfg.helloMr("Luigi")); // will println 'Hello Mr. Luigi!'
Disabling parameters expansion
The parametrized properties feature can be disabled if the user doesn’t find it convenient for some reason.
This can be done using the @DisableFeature
annotation:
public interface Sample extends Config {
@DisableFeature(PARAMETER_FORMATTING)
@DefaultValue("Hello %s.")
public String hello(String name);
// will return "Hello %s." ignoring the parameter.
}
The @DisabledFeature
annotation can be applied on method level and/or on
the interface level. When applied on the interface level, it will apply to all
the methods of the interface:
@DisableFeature(PARAMETER_FORMATTING)
public interface Sample extends Config {
@DefaultValue("Hello %s.")
public String hello(String name);
// will return "Hello %s." ignoring the parameter.
}