Created
September 23, 2017 17:05
-
-
Save miquelbeltran/93b47c705caeb0dd4814f3f2b94965a2 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
| 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