nkiesel
04/05/2021, 6:01 PMgetFoo
which returns an object of type Foo
(and never returns null
) is Foo!
. Should I (a) ignore this and use val foo = getFoo()
(b) use val foo: Foo = getFoo()
or (c) val foo = getFoo()!!
nanodeath
04/05/2021, 6:04 PMnanodeath
04/05/2021, 6:04 PMC
emoji đnkiesel
04/05/2021, 6:09 PMgetFoo
was re-implemented in Koltinchristophsturm
04/05/2021, 6:17 PMephemient
04/05/2021, 6:22 PMrequireNotNull(getFoo()) { "message" }
or checkNotNull(getFoo()) { "message" }
if I'm notchristophsturm
04/05/2021, 6:23 PMnkiesel
04/05/2021, 6:35 PMgetFoo
ever breaks it's promise and returns null
. but (b) and (c) at least then throw the exception at the definition instead of at the first usage.nkiesel
04/05/2021, 6:36 PMephemient
04/05/2021, 6:39 PMephemient
04/05/2021, 6:40 PMnkiesel
04/05/2021, 6:50 PM_foo
is what is required to make that work as I expected).ephemient
04/05/2021, 7:04 PMnkiesel
04/05/2021, 7:23 PMephemient
04/05/2021, 7:25 PMephemient
04/05/2021, 7:25 PMgetFoo()
defined in a parent classephemient
04/05/2021, 7:26 PMnkiesel
04/05/2021, 7:37 PM_foo
is defined before it's first use should do the trick, no? (And yes: I realize that this could break existing code)ephemient
04/05/2021, 7:44 PMnkiesel
04/05/2021, 8:12 PMephemient
04/05/2021, 8:21 PMephemient
04/05/2021, 8:22 PMFoo._foo
is initialized first, then Foo.foo
which calls Bar._foo
which is not yet initialized, then finally Bar._foo
ephemient
04/05/2021, 8:35 PMPeter Ertl
04/07/2021, 9:44 PMPeter Ertl
04/07/2021, 9:44 PM