val users = mutableListOf(null) users.add(User("svtk")) Error: Type mismatch: inferred type is User but Nothing? was expected Error: Type mismatch: inferred type is User but Nothing? was expected
String getDescription() } val session = Session() val description: Boolean = session.description Compiler error: Type mismatch: inferred type is String! but Boolean was expected
this.description = description; } } @NonNull by default val session = Session() session.setDescription(null) Warning: Expected type doesn’t accept nulls in Java, but the value may be null in Kotlin
this.description = description; } } @NonNull by default val session = Session() session.setDescription(null) Error: Null can not be a value of a non-null type String
Intrinsic checks is generated by the compiler throws an exception if session.description is null Intrinsics.checkExpressionValueIsNotNull( description, "session.description");
= mutableListOf<Customer>() fun getCustomers(): List<Customer> = customers } val customers = Shop.getCustomers() customers.add() you can’t shoot yourself in the foot any longer