Why getting class in Kotlin using double-colon (::)?

In Kotlin you can write Object::class, which will give you a KClass. KClass is not equivalent to the class Class that we know from Java.
If you want to get the Java Class class you can write Object::class.java – i.e.:
println("string"::class.java)

Also in java, .class is not a method or a member – it is a special directive for the compiler to access the class.
I guess each language select the syntax that makes most sense for it, and kotlin’s creators decided to use ::

:: in Kotlin is about meta-programming, including method references, property references and class literals.
See discussion about class literals.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)