unlok - unlock your JVM
a property/method accessor library for the JVM, written in Kotlin.
how to import
you can import unlok from maven central just by adding it to your dependencies:
gradle
repositories {
mavenCentral()
// Koffee repository, an Unlok dependency
maven("https://maven.hackery.site")
}
dependencies {
implementation("me.xtrm:unlok:{VERSION}")
}
how to use
Note: you can see more examples in our tests source set.
accessing a field
class DeclaringClass { companion object { @JvmStatic private val privatedName: String = "John" } private val index: Int = 9 } fun access() { // name infered from delegation val privatedName by DeclaringClass::class.field<String>() println(privatedName) val instance = DeclaringClass() // use `var` to modify the variable, even if it is final var index by DeclaringClass::class.field<Int>(ownerInstance = instance) index = 10 println(index) }
accessing a method
class DeclaringClass { companion object { @JvmStatic private fun getState() = "sleeping" } private fun isGaming(wearingSocks: Boolean) = !wearingSocks } fun access() { // name infered from delegation val getState by DeclaringClass::class.method<String>() println(getState()) val instance = DeclaringClass() val isGaming by DeclaringClass::class.method<Boolean>(ownerInstance = instance) println(isGaming(true)) }
troubleshooting
if you ever encounter any problem related to this project, you can open an issue describing what the problem is. please, be as precise as you can, so that we can help you asap. we are most likely to close the issue if it is not related to our work.
contributing
you can contribute by forking the repository, making your changes and creating a new pull request describing what you changed, why and how.
licensing
this project is under the ISC license.