https://kotlinlang.org logo
Title
b

brabo-hi

07/31/2018, 1:27 AM
"Mutable function parameter are not supported in Koltin" : how can we change object (or string) we're receive in another function ?
a

adam-mcneilly

07/31/2018, 1:32 AM
You could do something like this:
val myNewString = passedInString
and then do whatever you want with your new variable.
b

brabo-hi

07/31/2018, 1:49 AM
The think i don't to return something from the function. So what is the best way to send either a pointer or a reference to the string passed in parameter
t

thymecypher

07/31/2018, 1:58 AM
You generally don't want to do that which is why you generally can't in Kotlin - methods with side effects are not usually good.
2
If you want to modify a mutable using another object, you can modify the class to have a function that accepts the other object and modifies itself (if you control the mutable class), add an extension to the mutable method that takes the object and modifies itself (if you don't control the mutable) or create a method that takes both objects and produces a result of the two objects.
👍 1
Which one you choose all depends on your code style.
a

arekolek

07/31/2018, 7:40 AM
So what is the best way to send either a pointer or a reference to the string passed in parameter
Why would you need that? Just because it's
val
doesn't mean it's immutable, for example if it's a
val x: MutableList<String>
, you can still add and remove elements of
x
val
is like
final
in java and means you can't reassign it
k

karelpeeters

07/31/2018, 8:30 AM
And
fun set(x: Int) { x = 3 }
doesn't do anything in Java either.