https://blog.jetbrains.com/kotlin/2017/04/kotlin-1-1-2-is-out/ When I saw the news, I remembered the story that Kotlin's val, which was taught by a lead engineer in the field who had participated before, is an Immutable object in Java. At that time, I was told about each classification of Java and Kotlin's ʻImmutable / Mutable / Const / Variable`, but I forgot until I saw the news w ~~
So, what I remembered is not a memory but a record while it is hot, and it is likely to be completely forgotten during Golden Week, so Java and Kotlin's ʻImmutable / Mutable / Const / Variable` classifications I'll write it down.
It's a long time ago, so there may be some mistakes, so I'd appreciate it if you could point it out.
- Const ........... companiaon object { const val }
- Variable
- Immutable ..... val
- Mutable ....... var
It will be.
However, as a Kotlin language specification,
- Variable
- Immutable ..... val
- Const ....... companiaon object { const val }
- Mutable ....... var
However, it will be correct.
By the way, Kotlin's constant expression method
companion object {
const val HOGE = "hoge"
}
I write it like this.
Classification as language use
- Variable
- Immutable ..... final
- Const ....... static final
- Mutable .......Ordinary variables
It will be.
However, the idea is the same as Kotlin,
- Const
- Variable
- Immutable
- Mutable
Since the classification of is correct, I think it is better to be aware of this.
-constant...........The same value is always entered (≒ literally named)
-variable
-Immutable.........It doesn't change from the first one. What comes in first will change.
-variable.........It changes from the first one. When, how many times it changes depends on the implementation.
It will be. I personally find this classification fairly easy to understand and remember.
To be honest, until I learned this, I've heard the term ʻImmutable, but I don't use it. With that feeling, I was conscious of only two types,
Const / Variable`.
This kind of classification is not included in reference books (I'm sorry if I did), so it was very helpful.
The fact that I was taught to use the correct language but forgot it is proof that I haven't learned it yet.
Be careful ^ ^
Recommended Posts