Advertisement
Guest User

Untitled

a guest
May 18th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.74 KB | None | 0 0
  1.  
  2.  
  3. In Kotlin val declares final, read only, reference - and that is exactly what compiler error is telling you with
  4.  
  5.     Val cannot be reassigned
  6.  
  7. Once you assign value to val, it cannot be changed. If you want to be able to reassign it you have to declare it as var
  8.  
  9. In Kotlin method parameters are implicitly declared as final val, so you cannot reassign them just like you could in Java.
  10.  
  11. But the core error in your code is that you are trying to swap method parameters. Since method parameters are passed by value and not by reference what you want to achieve is impossible in Kotlin (just as well as it is impossible in Java). Even if you would reassign parameters inside method call original variables passed to the method would not change.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement