Colton Idle
10/07/2019, 11:11 AMspand
10/07/2019, 11:15 AMspand
10/07/2019, 11:15 AM!! in my codemarstran
10/07/2019, 11:16 AMrequireNotNull expresses intent more clearly.sindrenm
10/07/2019, 11:30 AMrequireNotNull and checkNotNull express intent more clearly, or when it makes sense just using `if`s with smart-casting. 😎Burkhard
10/07/2019, 2:30 PM!! is to tell kotlin that a platform type is not null, e.g. someJavaCall()!!elizarov
10/08/2019, 2:32 PM!! as “require not null”Colton Idle
10/08/2019, 4:49 PMDonn walks through why Kotlin’s Not Null Assertion Operator (!!) is a code smell and what you can do to alleviate it.
elizarov
10/08/2019, 4:55 PMColton Idle
10/08/2019, 4:56 PMcedric
10/09/2019, 11:04 PM!!, except maybe in tests.cedric
10/09/2019, 11:06 PMnull (e.g. a configuration file should be part of the distribution). Your app is going to crash if that thing is null, so it’s all a matter of how you want to crash.Colton Idle
10/09/2019, 11:39 PMelizarov
10/10/2019, 1:54 AM?: error("This should not happen"). I guess a project might have a policy to provide a better message that includes a context in this case. That would be a material improvement over !!. Without additional context in a message I see no benefit in writing longer code, though.sindrenm
10/10/2019, 8:56 AM!!. 👍spand
10/10/2019, 8:57 AMsindrenm
10/10/2019, 10:15 AMrequire vs check? I … don't know, I guess I just remember that require is in the context of arguments, where check is in the context of state, but I'm not sure why. 😛Colton Idle
11/06/2019, 9:24 AMsindrenm
11/06/2019, 9:31 AMrequireNotNull<T?> returns the T (non-nullable, so you could potentially do this:
val value = requireNotNull(nullableValue)
// use value henceforthsindrenm
11/06/2019, 9:33 AMrequireNotNull(value) calls to wherever you're accessing value, but I often find it nicer to just put it in a local val and “be done with it”.