https://kotlinlang.org logo
k

Klitos Kyriacou

06/07/2023, 8:53 AM
When you have a Java method
public Foo foo()
, which is known to return non-null but is not annotated as such, what is the preferred way to tell Kotlin that the value you assign is definitely non-nullable? (1)
val x: Foo = foo()
or (2)
val x = foo()!!
1️⃣ 10
2️⃣ 4
j

Javier

06/07/2023, 9:34 AM
explanation for me is unrelated tho, I prefer to be explicit with types as when I am using GitHub, it has no hints to know the exact type.
c

christophsturm

06/07/2023, 10:38 AM
if I have other reasons to specify the type I do 1, but just for nullability I do 2.