mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 10:38:19 +08:00
docs(sample): Add sample codes. 🥚
This commit is contained in:
@@ -45,6 +45,30 @@ Check out some code demonstrations [HERE](demo/src/main/java/cc/carm/lib/configu
|
||||
|
||||
For more examples, see the [Development Guide](.doc/README.md).
|
||||
|
||||
```java
|
||||
public class Sample {
|
||||
|
||||
@HeaderComment("Configurations for sample")
|
||||
interface SampleConfig extends Configuration {
|
||||
@HeaderComment("Configure your name!") // Header comment
|
||||
ConfiguredValue<String> NAME = ConfiguredValue.of("Joker");
|
||||
@InlineComment("Enabled?") // Inline comment
|
||||
ConfiguredValue<Boolean> ENABLED = ConfiguredValue.of(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 1. Make a configuration provider from a file.
|
||||
ConfigurationProvider<?> provider = EasyConfiguration.from("config.yml");
|
||||
// 2. Initialize the configuration classes or instances.
|
||||
provider.initialize(SampleConfig.class);
|
||||
// 3. Enjoy using the configuration!
|
||||
SampleConfig.ENABLED.set(false);
|
||||
System.out.println("Your name is " + SampleConfig.NAME.getNotNull() + " !");
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
### Dependencies
|
||||
|
||||
#### Maven Dependency
|
||||
|
||||
Reference in New Issue
Block a user