Boolean vs java.lang.Boolean

I encountered a subtle difference between Boolean and other primitives:

	@Test
	fun test() {
		println(java.lang.Boolean::class.java.name)
		println(Boolean::class.java.name)
		println(java.lang.Number::class.java.name)
		println(Number::class.java.name)
		println(java.lang.String::class.java.name)
		println(String::class.java.name)

		println(java.lang.Boolean::class.qualifiedName)
		println(Boolean::class.qualifiedName)
		println(java.lang.Number::class.qualifiedName)
		println(Number::class.qualifiedName)
		println(java.lang.String::class.qualifiedName)
		println(String::class.qualifiedName)
	}

Prints:

java.lang.Boolean
boolean
java.lang.Number
java.lang.Number
java.lang.String
java.lang.String
kotlin.Boolean
kotlin.Boolean
kotlin.Number
kotlin.Number
kotlin.String
kotlin.String

Does anyone know why?

Boolean is a primitive wrapper. Number and String are not. If you compared with Integer/Int you’d see the same pattern.

println(java.lang.Integer::class.java.name) // java.lang.Integer
println(Int::class.java.name) // int
3 Likes
            Boolean::class.javaPrimitiveType,
            Boolean::class.javaObjectType,

try these two types