https://kotlinlang.org logo
Title
k

karelpeeters

06/19/2019, 9:13 PM
To simplify the compiler code.
:thread-please: 4
f

Florian

06/19/2019, 9:38 PM
I mean why do normal operators need these functions in the first place
Java doesnt have that
k

karelpeeters

06/19/2019, 9:39 PM
Another way to think about it: there are no normal operators, there is only operator overloading.
Java doesn't have operator overloading so they were forced to create special cases for primitives and strings.
Kotlin can go the elegant route and define everything in Kotlin source code, which simplifies compiler code.
f

Florian

06/19/2019, 9:40 PM
Ok, I think I get it
Thank you
Just one more thing I don't get
where are the implementation for these methods?
they are just declared in the file
k

karelpeeters

06/20/2019, 7:33 PM
I can't really find it, but it's just somewhere deep in the compiler source code.
But there's no real "implementation", it just converts to an
iadd
bytecode operation on the JVM or a
+
on JS.
f

Florian

09/05/2019, 2:16 PM
I want to pick this up one more time
I understand WHY they don't have bodies, but how can they be DECLARED inside a kt file without a body
If the class is not abstract
Do those files not follow the same compiler rules?
k
If you follow that down it expands to a list of intrinsics, one for each primitive type.
So no, they don't follow the normal rules.
(
IADD
is literally just an integer, so that's what it actually ends up as, bytecode)
f

Florian

09/05/2019, 6:47 PM
Oh wow, thank you for the effort!
k

karelpeeters

09/05/2019, 6:47 PM
I wanted to know as well!
It had been on my todo list for 3 months 😄
Out of curiosity, why do you care so much? (not trying to be discouraging, being curious is good)
f

Florian

09/05/2019, 6:50 PM
Because I have a Kotlin beginner tutorial running on my YouTube channel
So I need to know some details that I usually wouldn't care about
k

karelpeeters

09/05/2019, 6:52 PM
Hmm I see. I void just avoid it entirely, no one asks why
+
in Java works either, or
Object.hashcode
or that kind of stuff. Same in Pyhton.
f

Florian

09/05/2019, 6:54 PM
In one of the 1st parts we have looked into the Primitives.kt file and now we learn about functions, so I want to clarify why the functions in there don't have bodies
To avoid confusion
I don't want to explain it in detail, I just want to mention it
Often, these small details require most of the research time
And I am not a professional, I always just learn in the process
As you can tell from my noob questions
k

karelpeeters

09/05/2019, 8:43 PM
I see.