Alin B.
07/10/2018, 7:47 AMclass Person(val firstName: String, val lastName: String, var age: Int)
and avoiding null means that whenever I instantiate it, I need to pass default values? So maybe have firstName="", lastName="" and age=0?Lucas Ł
07/10/2018, 7:50 AMclass Person(val firstName: String="", val lastName: String="", var age: Int=0)
and you don't need to set them when instantiating/using the constructor, for `val`s however keep in mind they are final
gildor
07/10/2018, 7:51 AMAlin B.
07/10/2018, 7:56 AMgildor
07/10/2018, 8:00 AMbut I haven’t done it and now I wonder why...Because it’s a lot of boilerplate code, for class constructors or for method arguments. Also java doesn’t support default method params, so everyting become even worse for a method with many nullable params, because you have to overload this method to make API more pleasant
Alin B.
07/10/2018, 8:03 AMgildor
07/10/2018, 8:05 AMAlin B.
07/10/2018, 8:05 AMvar
should only be used if really needed and stick with val
instead. What would be the reason for this?gildor
07/10/2018, 8:06 AMAlin B.
07/10/2018, 8:08 AMfinal
in java?gildor
07/10/2018, 8:08 AMAlin B.
07/10/2018, 8:10 AMList<Items>
as field. that should also be declared as new empy List
so it's not null?gildor
07/10/2018, 8:11 AMemptyList<Items>()
as default valueval list: List<Items>? = null
list.orEmpty().doSomething()
Alin B.
07/10/2018, 8:14 AMgildor
07/10/2018, 8:19 AMLucas Ł
07/10/2018, 8:22 AMgildor
07/10/2018, 8:27 AMAlin B.
07/10/2018, 8:29 AMgildor
07/10/2018, 8:30 AMAlin B.
07/10/2018, 8:39 AM