LeoColman
05/11/2020, 3:38 PMAlways explicitly specify function return types and property types (to avoid accidentally changing the return type when the implementation changes)It's kind of ambiguous for me if it applies to
Unit
as well.
As I understand, it's meant for
fun test(someVar:String) = when(someVar){
"a" -> 10
else -> 20
}
where you can easily break the Int return.
Would we always specify that a certain method returns Unit, even if it's redundant?araqnid
05/11/2020, 3:45 PMfun
defined as a block (not with =
) is explicitly returning Unit
if its return type is not otherwise specified. At least, this is significantly different from the “inferred return type” of functions defined as expressions, and I never put the : Unit
in. I do always define functions returning Unit as blocks, though.