Skip to content

Instantly share code, notes, and snippets.

@ruwanka
Created March 21, 2018 17:16
Show Gist options
  • Save ruwanka/bff2281400b886ffded54f8edd1b331b to your computer and use it in GitHub Desktop.
Save ruwanka/bff2281400b886ffded54f8edd1b331b to your computer and use it in GitHub Desktop.
Trying out Kotlin support for java Reflection API
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