Declare configuration types using @Configuration
masterTo define a configuration type in ConfigLib, you can use either a Java record or a non-generic class annotated with @de.exlll.configlib.Configuration.
Requirements for Classes:
- Must have a no-args constructor (can be
private). - Inner classes (non-static) are not supported because they lack the required implicit constructor.
- It is highly recommended to initialize all fields with non-null default values.
Requirements for Records:
- Records are supported natively. To provide default values when using the
updatemethod (if the file does not exist), add a no-args constructor that calls the canonical constructor with your desired defaults.
// Using a class
@Configuration
public final class MyConfig {
private int value = 42;
// No-args constructor required
private MyConfig() {}
}
// Using a record
@Configuration
record User(String name, String email) {
// No-args constructor for default values during 'update'
User() {
this("John Doe", "john@doe.com");
}
}