Created
September 25, 2016 05:29
-
-
Save Jire/df9c99fac5e4d3f35e1a6c517716f989 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| inline fun <reified T : Any, DELEGATE : Any> findDelegate( | |
| instance: T, delegatingTo: KClass<DELEGATE>): DELEGATE? { | |
| for (prop in T::class.declaredMemberProperties) { | |
| val javaField = prop.javaField ?: continue | |
| javaField.isAccessible = true // is private, have to open that up | |
| if (delegatingTo.java.isAssignableFrom(javaField.type)) { | |
| @Suppress("UNCHECKED_CAST") | |
| return javaField.get(instance) as DELEGATE | |
| } | |
| } | |
| return null | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment