1
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:
2024-01-03 23:09:28 +08:00
parent d0af3e436f
commit db19531c13
3 changed files with 79 additions and 1 deletions
+24
View File
@@ -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