Is there any possibility to disable nullability ch...
# announcements
Is there any possibility to disable nullability change for method return?
No, why would you? You're always allowed to narrow returns.
I need such logic for external declarations only, where in my case narrow return is mistake in common case.
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.
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: