Is there any possibility to disable nullability ch...
# announcements
t
Is there any possibility to disable nullability change for method return?
r
No, why would you? You're always allowed to narrow returns.
t
I need such logic for external declarations only, where in my case narrow return is mistake in common case.
d
Doesn't change anything for the caller, and in the case null is to be returned there will be a compile time error. Only thing is when you want to override again, in which case there would also be an error at compile time.
s
I don’t see the problem. Whenever you work with an instance of A you have to make certain that you can handle a null value and a non-null value. So when a subclass of A only returns always/guaranteed a non-null value that doesn’t introduce any problem for the code. You could even have a subclass that is guaranteed to return null:
Copy code
class A3:A() {
	override fun nullableFun():Nothing? = null //Nothing? only contains null
}
here a playground link where I played a bit around with this idea: https://pl.kotl.in/u5NfAbAGZ