

The price, though, is that this API is not part of the default stdlib and requires you to include an additional package kotlin-reflect.jar in your project, which to date represents an extra 2.7MB to your app, while Java reflection API is natively part of the JVM ( smaller alternatives exist though, but with limited functionalities). On the other hand, Kotlin reflection offers an API that is not only consistent with your Kotlin code, but also exposes the language specificities that convinced us to give up Java in the first place.
#Java reflection invoke method without parameters code#
Adding coroutines to the mix takes it one step further as it reveals the clever byte code manipulation that gave us those powerful features. But the truth is that due to some differences in the way objects and functions work in Kotlin, there are some subtle peculiarities which make it risky to navigate between the two worlds. it is tempting to think that you can easily mix them when your code only runs on a JVM. Reflection can be a clever way to address some problems in a generic manner, and since Java and Kotlin both offer functions to manipulate classes, objects, properties, functions, etc.

