Erik
08/26/2020, 8:17 AM?
as an expression suffix to coerce the expression to be of nullable type?
Examples:
var x = 1?
-> inferred type = Int?
, so no need to type var x: Int? = 1
. Later you can always set x = null
.
someQuery()?
-> inferred type = nullable return type of someQuery()
. If that function already returns a nullable type, then a linter warning should be shown that the ?
suffix is redundant.Erik
08/26/2020, 8:17 AMErik
08/26/2020, 8:17 AMErik
08/26/2020, 8:17 AMCLOVIS
08/26/2020, 12:50 PMval foo: Something? = something()
Erik
08/26/2020, 12:54 PMsomething()
returns Something
normallyCLOVIS
08/26/2020, 2:03 PM1?
, "something"?
), but for functions results it might look a little bit too much like ?.
Erik
08/26/2020, 2:10 PMErik
08/26/2020, 2:11 PMErik
08/26/2020, 2:11 PMErik
08/26/2020, 2:11 PMHanno
08/26/2020, 2:36 PMCLOVIS
08/26/2020, 3:08 PM1
is, but if you want Int?
you have to declare the type. For such examples, it's kind of like writing 1f
instead of 1.toFloat()
, it carries the same meaning but is much smaller.CLOVIS
08/26/2020, 3:09 PMHanno
08/26/2020, 3:17 PMYoussef Shoaib [MOD]
08/28/2020, 8:51 AMval <T: Any> T.nullable: T? get() = this