HiddenLayer555@lemmy.ml to Programming Humor@lemmy.worldEnglish · 15 days agoWhy make it complicated?lemmy.mlimagemessage-square13fedilinkarrow-up130arrow-down13file-textcross-posted to: programmerhumor@lemmy.ml
arrow-up127arrow-down1imageWhy make it complicated?lemmy.mlHiddenLayer555@lemmy.ml to Programming Humor@lemmy.worldEnglish · 15 days agomessage-square13fedilinkfile-textcross-posted to: programmerhumor@lemmy.ml
minus-squaremacniel@feddit.orglinkfedilinkEnglisharrow-up5·15 days agoI see your TypeScript and raise you kotlin: var a: String
minus-squareuranibaba@lemmy.worldlinkfedilinkEnglisharrow-up1·15 days agoWhat’s up with that syntax? Why the use of var here?
minus-squaremacniel@feddit.orglinkfedilinkEnglisharrow-up3·edit-215 days agoKotlin knows mutable and immutable variables. var indicate mutables and val would indicate immutables (comparable with the final modifier in java and const in JavaScript/TypeScript).
minus-squareuranibaba@lemmy.worldlinkfedilinkEnglisharrow-up1·15 days agoSo a var can start as a string and later be an integer?
minus-squaremacniel@feddit.orglinkfedilinkEnglisharrow-up2·15 days agoNo, the type is strict and fixed.
minus-squareguillem@aussie.zonelinkfedilinkEnglisharrow-up2·15 days agoI don’t know Kotlin but in other languages “(im)mutable” refers to the value, not the type.
I see your TypeScript and raise you kotlin:
var a: String
What’s up with that syntax? Why the use of var here?
Kotlin knows mutable and immutable variables.
var
indicate mutables andval
would indicate immutables (comparable with thefinal
modifier in java andconst
in JavaScript/TypeScript).So a var can start as a string and later be an integer?
No, the type is strict and fixed.
I don’t know Kotlin but in other languages “(im)mutable” refers to the value, not the type.