gildor
12/07/2017, 2:56 AMlovis
12/07/2017, 8:12 AMgildor
12/07/2017, 8:13 AMbdawg.io
12/07/2017, 9:44 AM=
a property to multiple typesgildor
12/07/2017, 9:49 AMbdawg.io
12/07/2017, 9:50 AMvar foo: A = ...
set(b: B) { ... }
gildor
12/07/2017, 9:52 AMfun getFoo(): A
fun setFoo(b: B)
var foo: A
, but now you want to have also B setter (for case something like A(b)
), so to cover such case you must add fun setFoo(b: B)
or replace property with methodsfoo
usages and again, you cannot use property syntaxlovis
12/07/2017, 10:55 AMset
at all, but give meaningful names to functions .
I'd always prefer an extension function for this:
myThing.foo = bar.asFoo()
(or something like that, and it also works well with dsls)There are also some cases where you may want to accept a null value on a non-nullable property and convert the null into some default value for the getterthis comment on this is especially freaking me out...