dalexander
10/22/2015, 12:25 PMpublic class ProblemClass<T>(){ //changing this to T: Any? resolves the issues in this example
//If T compile error: Error:(3, 23) Kotlin: Null can not be a value of a non-null type T
//If T? warns: Warning:(4, 20) Kotlin: 'T' has a nullable upper bound. This means that a value of this type may be null. Using 'T?' is likely to mislead the reader
var someItem: T? = null
fun foo() {
if(someItem == null) {
System.out.println("Oh null")
} else {
//I would expect this to be smartcast to non-null T
//Error:(12, 28) Kotlin: Type mismatch: inferred type is T? but T was expected
noNullsAllowed(someItem!!)
}
}
fun noNullsAllowed(t: T) {
}
}