Null object: Difference between revisions
Content deleted Content added
Added Kotlin |
|||
Line 752: | Line 752: | ||
For more detail on K's concept of typed nulls, see http://code.kx.com/wiki/Reference/Datatypes#Primitive_Types |
For more detail on K's concept of typed nulls, see http://code.kx.com/wiki/Reference/Datatypes#Primitive_Types |
||
=={{header|Kotlin}}== |
|||
Kotlin distinguishes between non-nullable types and nullable types. The latter are distinguished from the former by a '?' suffix. Only nullable types have a 'null' value indicating that they don't currently refer to an object of their non-nullable equivalent. |
|||
In addition, Kotlin has a Nothing type which has no instances and is a sub-type of every other type. There is also a nullable Nothing? type whose only value is 'null' and so, technically, this is the type of 'null' itself. |
|||
Here are some examples: |
|||
<lang scala>// version 1.1.0 |
|||
fun main(args: Array<String>) { |
|||
val i: Int = 3 // non-nullable Int type - can't be assigned null |
|||
println(i) |
|||
val j: Int? = null // nullable Int type - can be assigned null |
|||
println(j) |
|||
println(null is Nothing?) // test that null is indeed of type Nothing? |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
3 |
|||
null |
|||
true |
|||
</pre> |
|||
=={{header|Lasso}}== |
=={{header|Lasso}}== |