Debian Codegraph @

owner-site/site/docs/parametrized-properties.md

raw symbols SCIP
1 ---
2 layout: docs
3 title: Parametrized properties
4 prev_section: importing-properties
5 next_section: type-conversion
6 permalink: /docs/parametrized-properties/
7 ---
8
9 Another neat feature, is the possibility to provide parameters on method
10 interfaces.
11 The property values shall respect the positional notation specified by the
12 [`java.util.Formatter`][fmt] class:
13
14 [fmt]: http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax
15
16 ```java
17 public interface Sample extends Config {
18 @DefaultValue("Hello Mr. %s!")
19 String helloMr(String name);
20 }
21
22 Sample cfg = ConfigFactory.create(Sample.class);
23 print(cfg.helloMr("Luigi")); // will println 'Hello Mr. Luigi!'
24 ```
25
26 Disabling parameters expansion
27 ------------------------------
28
29 The parametrized properties feature can be disabled if the user doesn't find it
30 convenient for some reason.
31
32 This can be done using the `@DisableFeature` annotation:
33
34 ```java
35 public interface Sample extends Config {
36
37 @DisableFeature(PARAMETER_FORMATTING)
38 @DefaultValue("Hello %s.")
39 public String hello(String name);
40 // will return "Hello %s." ignoring the parameter.
41
42 }
43 ```
44
45 The `@DisabledFeature` annotation can be applied on method level and/or on
46 the interface level. When applied on the interface level, it will apply to all
47 the methods of the interface:
48
49 ```java
50 @DisableFeature(PARAMETER_FORMATTING)
51 public interface Sample extends Config {
52
53 @DefaultValue("Hello %s.")
54 public String hello(String name);
55 // will return "Hello %s." ignoring the parameter.
56
57 }
58 ```