Linked Questions
18 questions linked to/from What is the difference between var and val in Kotlin?
3
votes
1
answer
6k
views
Kotlin: Should I use val instead of var? [duplicate]
Let's say I have something like this:
var x : String = "str"
// here do some with x, but not assign new value to it
Then Android Studio tells me that x should be declared with val, not var.
I know ...
2
votes
1
answer
1k
views
Spring Boot Kotlin entity property val vs var [duplicate]
I am learning Spring Boot with kotlin and I am so confused with the usage of var or val for entity property. In some tutorial they use val and the other use var. So I don't know which is the right one ...
-1
votes
1
answer
774
views
To use var or val in kotlin android? [duplicate]
In which case we have to use val instead of var ? I know val is when we know the value is not going to change. But I am under the impression that var is good for all case. Is that true ?
In others ...
1
vote
1
answer
86
views
Hello guys, can someone explain to me the difference between a reference and a referenced object? [duplicate]
can someone explain to me the difference between a reference and a referenced object?
Notice that the type of the variable reference (var, val) relates to the reference
itself, not the properties of ...
23
votes
3
answers
12k
views
Variables in Kotlin, differences with Java: 'var' vs. 'val'?
I am trying to learn Kotlin. What is val, var and internal in Kotlin compared to Java?
In Java:
RadioGroup radioGroup;
RadioButton button;
Button submit;
After converting it shows:
internal ...
8
votes
2
answers
3k
views
problems using databinding: val vs var and the use invalidateAll()
This is actually 2 questions.
I noticed that databinding doesn't work if in the Person data class I set the name parameter to be val instead of var. The code will break with the following error:
...
8
votes
2
answers
10k
views
How to register an InstanceCreator with Gson in Kotlin?
I can use Code 1 to save MutableList<MDetail> to json string using Gson correctly,
But I get the error when I try to restore MutableList<MDetail> object from json string with Code 2.
I ...
2
votes
4
answers
2k
views
Why Kotlin uses the word "val" to stand for constant?
I really want to know why Kotlin use the word val to stand for constant?
If var means variable.val means what ? val means var + l or val is only one word for short?
In the Kotlin Documentation,we ...
0
votes
1
answer
14k
views
Unable to get data from sqlite database
The problem is that when I run my code the app is stopping with an error (java.lang.RuntimeException: Unable to start activity ComponentInfo{com.twixt.pranav.pos/com.twixt.pranav.pos.View.Activity....
5
votes
2
answers
3k
views
Sealed class in Kotlin, Incompatible types error
I have the following Kotlin code. A sealed class called Animal, and two object classes Dog and Cat inherits from the sealed class Animal. I am getting this error in the when clause in the is Cat case.
...
5
votes
3
answers
4k
views
How to initialize a property with an unknown type in Kotlin?
I'm a beginner in Kotlin and I'm actually doing an Androïd application in Kotlin. I have to initalize some properties whose values are unknown (it isn't but it's hard to define from now) so I'd like ...
1
vote
1
answer
4k
views
PSQLException: ERROR: insert or update on table "expenses" violates foreign key constraint "expenses_user_id_fkey"
I am working on simple Spring Boot service with Kotlin, and PostgreSql. I use JPA. Currently I have two tables "users", and "expenses", "expenses" table have reference to "users" id:
CREATE TABLE ...
0
votes
1
answer
888
views
How can I store document field data from a particular collection in firestore database to a string variable in kotlin
I want to get data from the cloud firestore and have to store it to a string variable but unable to do so and need help.
This is below code
val db = FirebaseFirestore.getInstance()
val ...
0
votes
1
answer
334
views
How can you change the value of a mutable list/map/array when its defined as a val type in Kotlin
I'm new to Kotlin and I've been reading a lot about how val is read-only and var is mutable. That's fine i get it. But what's confusing is when you create a mutable lsit/map/array and you've assigned ...
0
votes
1
answer
437
views
Dynamically changing ListView item size kotlin
I'm trying to change height and width of ListView item programmatically, but I'm getting an "val cannot be reassigned error", can you please tell me witch exact val can't be reassigned here and how ...