0

In PHP you can optionally make parameters pass by reference with an & in the function definition:

someFunction($byValue, &$byReference) {
    // $byValue is passed in by value
    // $byReference is passed in by reference due to the preceding &
}

Is this possible in Kotlin? If not, does anyone know if it's planned?

wheelmaker
  • 2,975
  • 2
  • 21
  • 32
  • 1
    See https://stackoverflow.com/a/54689951/1246282 – chrsblck Jan 03 '20 at 19:13
  • 2
    Does this answer your question? [Is Kotlin "pass-by-value" or "pass-by-reference"?](https://stackoverflow.com/questions/44515031/is-kotlin-pass-by-value-or-pass-by-reference) – Quinn Jan 03 '20 at 19:15
  • @Quinn yes the answer to my question can be derived from the question you linked though I don't see it as a direct duplicate as stated in the comment on your own answer. – wheelmaker Jan 03 '20 at 21:25
  • 1
    @wheelmaker Yes you're right, it is not a direct duplicate, just a similar question. Sorry for my phrasing – Quinn Jan 03 '20 at 21:28

1 Answers1

1

I believe that similar to Java, Kotlin is always pass-by-value and optional pass-by-reference is not possible.

wheelmaker
  • 2,975
  • 2
  • 21
  • 32
Quinn
  • 7,072
  • 7
  • 39
  • 61