Skip to content

Instantly share code, notes, and snippets.

@miquelbeltran
Created September 23, 2017 17:05
Show Gist options
  • Select an option

  • Save miquelbeltran/93b47c705caeb0dd4814f3f2b94965a2 to your computer and use it in GitHub Desktop.

Select an option

Save miquelbeltran/93b47c705caeb0dd4814f3f2b94965a2 to your computer and use it in GitHub Desktop.
import kotlin.reflect.full.findAnnotation
annotation class HelloName(val name: String)
abstract class Hello {
fun getName(): String {
val ann = javaClass.kotlin.findAnnotation<HelloName>()
return ann?.name ?: throw IllegalStateException("Missing annotation @HelloName")
}
}
@HelloName("World")
class Learn : Hello()
fun main(args: Array<String>) {
println("Hello ${Learn().getName()}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment