Created
March 21, 2018 17:16
-
-
Save ruwanka/bff2281400b886ffded54f8edd1b331b to your computer and use it in GitHub Desktop.
Trying out Kotlin support for java Reflection API
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
package com.ruwanka.kotlin.reflections | |
open class Person(val name: String, var age: Int) | |
class Student(name: String, age: Int, var school: String) : Person(name, age) | |
fun main(args: Array<String>) { | |
printTypeHierarchy(Student::class.java) | |
} | |
/** | |
* print type hierarchy of java class | |
*/ | |
private fun printTypeHierarchy(cls: Class<out Any>?) { | |
var clazz = cls; | |
while (clazz != null) { | |
println(clazz.name) | |
clazz = clazz.superclass as Class<out Any>? | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment