Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren+ 2
Is initialization necessary for val variables in Kotlin?
I know that the val variables can not change. This is similar to C++ constants. But I wonder if it's possible to declare a val without initialization. We're not "changing" it! We're just quantifying it separately from the declaration. I mean something like this val x:int ... x=1
2 Antworten
+ 2
Yeah ofc, if you don't initalize it intellij won't even allow you to run through
Also you can check it, you would get `blah` Is not initalized
maybe if you have java background you may have confusion like
```java
public String bruh
```
why this isn't possible in kotlin then well
```kt
lateint var bruh: String
```
which will answer your question
Koorosh Nobakhtfar
+ 3
Koorosh Nobakhtfar , i hope i understand you right. you can do like
val x = 1
...
or you can do like this:
val x1:Int = 1