C++ father tell me that JAVA is built on top of C+...
# compiler
a
C++ father tell me that JAVA is built on top of C++, so what language is Kotlin built on? everyone.
d

https://youtu.be/Ljr66Bg--1M?si=PpZNJ4JHv_yllBA0

a
when generate android apk, kotlin compile path is: Kotlin -> Java byte code -> apk?
👌 1
can Kotlin do "pass by reference" like C++?
d
Everything is passed by reference by default
Exceptions are primitive types and value classes
a
can you update this [Gemini answer](https://gemini.google.com/app/f1ce571ade99913c)?
d
AI is not reliable source of information
k
It's misleading to say "Everything is passed by reference by default". Kotlin is like Java when it comes to parameter passing. So, for example,
Copy code
fun foo(list: MutableList<String>) {
    list = arrayListOf<String>("bar")
}
If Kotlin was "pass by reference" in the same way as C++ and C#, then the above function
foo
would change the passed parameter
list
to a list containing an element "bar". But Kotlin is not pass-by-reference in this way. You can't change the value of a passed variable. I think what Dmitriy meant was that variables (except primitives) hold a reference to an object. So even though you pass the value of a variable to a function, that value is the reference of the object.
d
References to parameters are immutable (non-reassignable) The code from your snippet won't compile
👀 1
a
@Klitos Kyriacou show me your code playground, please
@Klitos Kyriacou @dmitriy.novozhilov how to realize the same effort for "pass by reference" like C++ in the Kotlin?
k
You have to be explicit in Kotlin, using for example a wrapper object: let's say you want a function that changes a passed value, then you have to keep that value inside an object:
Copy code
class Wrapper<T>(var value: T)

fun foo(x: Wrapper<Int>) {
    x.value = 456
}

int main() {
    val x = Wrapper(123)
    foo(x)
    check(x.value == 456)
}
This is not idiomatic Kotlin. In Kotlin, we prefer to keep things immutable, so we would probably in the above case just write a function that takes one value and returns another value, rather than mutating.
a
as your code, x is like "pass by value" in the C++. x is "pass by value" in the C++ in the fact.
👌 1
this do not have performance. teacher.
what's solution?
a
Why doesn’t it have performance?
a
if no reference, it is performance problem.