-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow private fields as properties #133
Comments
I don't have much experience with Kotlin—are there any other shortcomings that could be improved for Kotlin integration? I'd like to get a better picture as to maybe bundle a few improvements to facilitate usage from Kotlin. |
Aside from that, a benefit not only for Kotlin, but Java as well would be for the project to utilize the jetbrains annotations to mark nullability and contracts. IntelliJ is able to infer some of them, but proper definition is always better. |
- Use Field#setAccessible if a field is not private to make the code compatible with Kotlin constants without the need of the JvmField annotation.
As long as the field is static, it will be picked up by the default configuration data builder. Sample Kotlin code that will work with the next release: import ch.jalu.configme.Comment
import ch.jalu.configme.SettingsHolder
import ch.jalu.configme.SettingsManagerBuilder
import ch.jalu.configme.properties.PropertyInitializer
import ch.jalu.configme.utils.Utils
import java.nio.file.Paths
fun main(args: Array<String>) {
val path = Paths.get("./configme-kt-test.yml")
Utils.createFileIfNotExists(path);
val settings = SettingsManagerBuilder
.withYamlFile(path)
.configurationData(TitleSettings.javaClass)
.create()
println("App: ${settings.getProperty(TitleSettings.TITLE_TEXT)}")
}
object TitleSettings: SettingsHolder {
@Comment("Demo")
val TITLE_TEXT = PropertyInitializer.newProperty("title.text", "woof")
} Previously, |
- Use Field#setAccessible if a field is not private to make the code compatible with Kotlin constants without the need of the JvmField annotation.
Allowing for private fields would make usage from Kotlin less ugly.
In its current state, the library resolves all fields, private included, and just throws away fields that are inaccessible.
Simply inserting
Field#setAccessible(true)
above this line here:ConfigMe/src/main/java/ch/jalu/configme/configurationdata/ConfigurationDataBuilder.java
Line 115 in 1084f43
Will resolve this issue.
The text was updated successfully, but these errors were encountered: