Linked Questions

3 votes
1 answer
9k views

I would need to have one class reference another. Not create a copy of it but have an actual reference to an already existing instance. I might be able to explain it better with an example. Were we ...
Rares Dima's user avatar
  • 1,787
7743 votes
87 answers
2.8m views

I always thought Java uses pass-by-reference. However, I read a blog post which claims that Java uses pass-by-value. I don't think I understand the distinction the author is making. What is the ...
12 votes
4 answers
14k views

I am trying to create a swap function which takes in two parameters as shown below: fun swap(a :Int, b:Int) { } I call it like this: var a = 10 var b = 5 swap(a,b) // a should be ...
john doe's user avatar
  • 9,764
4 votes
3 answers
13k views

I have tried to set a property value as in the following snippet.This SO question is not answering the question. var person = Person("john", 24) //sample_text.text = person.getName() + ...
The_Martian's user avatar
  • 3,777
5 votes
3 answers
6k views

I am aware that an argument passed to a function will be seen as "val", even if the variable was initialized as "var". But this has been a problem for me. In this example code ...
DDD's user avatar
  • 77
1 vote
3 answers
1k views

Could someone explain why can't I change the value of var in that case ? fun main(args: Array<String>) { var number = 3 changeNumber(number) } fun changeNumber(number: Int) { number ...
discCard's user avatar
  • 531
0 votes
4 answers
1k views

I'm new to kotlin. I've got a problem with making a function that changes the value of the boolean. fun main () { var x = false functionWithBoolean(variable = x) } fun functionWithBoolean(...
Marcel's user avatar
  • 27
3 votes
1 answer
1k views

In Rust and Swift you can create a slice of either/both arrays and strings which doesn't make a new copy of the elements but gives you a view into the existing elements using a range or iterator and ...
hippietrail's user avatar
  • 17.3k
0 votes
1 answer
672 views

The question is in the title: In Kotlin, if an object is passed into a new instance of a class and then some properties are changed, will it change the properties in the original object? Image I've ...
Kek's user avatar
  • 391
0 votes
1 answer
598 views

var i = 0 arrayOf<CheckBox>(binding.chkBackup, binding.chkBackupEnc, binding.chkDrive, binding.chkDriveEnc, binding.chkMp3).forEach { it.setOnClickListener { chk -> ...
Oleg Gryb's user avatar
  • 5,309
1 vote
1 answer
306 views

I am trying to use apply function for assign a new value to a variable. when i try apply() to re-assign a value to a parameter of a data class it works correctly. but when i have not a data class it ...
Saeed Pakdelnia's user avatar
0 votes
1 answer
103 views

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 // $...
whmkr's user avatar
  • 3,095
1 vote
1 answer
91 views

I'm new to Kotlin and I don't know where I went wrong with this. fun swap(a:Int,b:Int):Unit{ a=a xor b b=b xor a a=a xor b } fun main() { var a =10 var b = 1000 // swap(a, b) ...
codemaivanngu's user avatar
0 votes
1 answer
99 views

I need to create multiple editTexts with logic to handle the format of the input. The different editTexts will bind to different variables and save to different properties of viewModel.home. The ...
zorigo's user avatar
  • 9