Add reflection utilities

This commit is contained in:
Jakob K
2021-06-28 00:26:16 +02:00
parent 4a14a29c3a
commit 23a5c4c0fd
2 changed files with 13 additions and 4 deletions

View File

@@ -0,0 +1,11 @@
package net.axay.kspigot.utils
/**
* Loads the value of the given field for this object.
*/
fun <T> Any.reflectField(field: String): T {
val reflectedField = this::class.java.getDeclaredField(field)
reflectedField.isAccessible = true
@Suppress("UNCHECKED_CAST")
return reflectedField.get(this) as T
}