requireNotNull or "!​!"?


hi Kotlin Team,

Is there a general guideline, when should one use requireNotNull and when “!!” to enforce notnullness?


I would say that requireNotNull() is best used for parameter validation (if you can’t simply use a non-null type - for example, if the contract of your function is "if parameter X is not null, parameter Y must be not null as well). In all other cases, it’s better to use !! because it’s more concise and easier fits into the middle of an expression.