In java, I am able to use getClass() and then retrieve simpleName from that class object without any issues.
String tag = someObject.getClass().getSimpleName(); // java code
But when converting to Kotlin, this causes warnings
Call uses reflection API which is not found in compilation classpath. Make sure you have kotlin-reflect.jar in the classpath
The kotlin code is
someObject::class.simpleName!! // kotlin code
What is the proper way of avoiding
kotlin.jvm.KotlinReflectionNotSupportedError ? Needs additional dependency to kotlin-reflect.jar. Maybe would be better use ::class.java.simpleName
The getSimpleName() method of java. lang. Class class is used to get the simple name of this class, as given in the sourcecode. The method returns the simple name of this class in the form of String. If this class is anonymous, then this method returns empty string.
here getInstance() method is called whenever we request for the Instance where we can add code if we want to do something when the instance is called from any where everytime.
Structural Equality ('==')== operator in Kotlin only compares the data or variables, whereas in Java or other languages == is generally used to compare the references. The negated counterpart of == in Kotlin is != which is used to compare if both the values are not equal to each other.
Use someObject::class.java.simpleName
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With