Created
January 11, 2019 23:49
-
-
Save adam-arold/bea811884b15ddee9112bdfd426199ec 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
// reified is not visible from Java | |
class EventBus { | |
inline fun <reified T : Event> subscribe( | |
noinline callback: (T) -> Unit) { | |
// ... | |
} | |
} | |
// @JvmSynthetic was designed for this purpose | |
interface EventBus { | |
@JvmSynthetic | |
fun <T: Event> subscribe(eventType: KClass<T>) | |
} | |
// extension functions are not visible on the same class | |
inline fun <reified T : Event> EventBus.subscribe( | |
noinline callback: (T) -> Unit) { | |
return subscribe( | |
klass = T::class, | |
callback = callback) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment