A
A
AlexF2018-01-21 17:15:01
Kotlin
AlexF, 2018-01-21 17:15:01

Links in Kotlin?

There is C++ code :

class ExampleClass {
public:
    int value;
    ExampleClass() { value = 0; }
}

void function(ExampleClass &obj) {
    obj.value = 1;
}

int main() {
    ExampleClass obj;
    function(obj);
    cout << obj.value << endl;
    return 0;
}

Please tell me the equivalent in Kotlin. The essence of the code, of course, is not the same, but it is necessary that when a class object changes in a function (or another class), it changes everywhere. Options like these are not suitable:
code
ExampleClass function(ExampleClass obj) {
    obj.value = 1;
    return obj;
}

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2018-01-21
@AleexF

At least he would say what exactly does not fit. Because this is exactly what will be a complete analogue (in Kotlin everything is a reference, you can’t put anything on the stack.

Y
Yerlan Ibraev, 2018-01-22
@mad_nazgul

Uh-uh
Your code is from Java, what does Kotlin have to do with it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question