public class Char private constructor() : Comparable<Char> {
public fun toInt(): Int
...
}
First of all, what is this even, and why does it compile? a concrete class with no implementation of methods?
Secondly, does
charArratOf('a', 'b', 'c')
create 3 instances of Char class?
Or, is there some magic
e
ephemient
09/20/2021, 3:01 AM
that builtin "implementation" is just a stub. on JVM the compiler emits
java.lang.Character
,
char
,
char[]
, etc. as appropriate.
u
ursus
09/20/2021, 3:21 AM
okay so
charArrayOf(..)
is then equal to the java
char[]
?
e
ephemient
09/20/2021, 4:19 AM
yes,
primitiveArrayOf()/PrimitiveArray
is exactly equivalent to Java's
primitive[]
, and
arrayOf<T>()/Array<T>
is exactly equivalent to Java's
T[]
u
ursus
09/20/2021, 4:48 AM
thanks
Id like how ask how does the Char class compile like that? Is there some special case in the compiler?
e
ephemient
09/20/2021, 4:51 AM
yes, builtins are hard-wired in the compiler
u
ursus
09/20/2021, 5:58 AM
thank you
c
CLOVIS
09/20/2021, 8:36 AM
It doesn't actually compile to anything, what you're looking at is more or less a “binding” that declares functions, similar to external interfaces, so the rest of your code can call these methods; but the real implementation is inside the compiler/runtime.