scala中查看类型
Scala Nothing Type
Scala无类型
It is a trait in Scala. Being a trait it does not have any instance, and is contained by every data set but is not a superclass. Nothing has found uses in functions that always return an exception to handle.
这是Scala的一个特征 。 作为特征,它没有任何实例,并且包含在每个数据集中,但不是超类。 在始终返回要处理的异常的函数中没有发现任何用处。
Scala Nil Type
Scala Nil类型
It is a list that has no element. Nil uses nothing as it is a subset. Nil's type is list[nothing].
它是一个没有元素的列表。 Nil不使用任何内容,因为它是一个子集。 Nil的类型为list [nothing] 。
var a = nil gives a lit[nothing]
Scala Null Type
Scala空类型
It is a trait that is used only by reference instances, not data instances. This means it is a subset of only reference class. Scala uses Option instead of Null as it is more effective. The value of the reference data types like objects etc is null, but this value is not valid for data types like Int, Float, etc.
这是一个特征 ,其仅由参考实例,而不是数据实例使用。 这意味着它只是参考类的子集。 Scala使用Option而不是Null,因为它更有效。 引用数据类型(如对象等)的值为null ,但此值对数据类型(如Int , Float等)无效。
Scala None Type
Scala无类型
It is the replacement of null in the option type of Scala. It has none that is initialized when no value is given.
它是Scala选项类型中 null的替换。 没有给出任何值时,不会初始化任何内容。
Example:
例:
object MyClass {
def main(args: Array[String]) {
println(null);
//println(none) // gives error : not found : value none
println(Nil)
}
}
Output
输出量
null
List()
Example of None in Scala
Scala中无的示例
object MyClass {
def main(args: Array[String]) {
//printing empty list
println(None.toList)
//checking whether None is empty or not
println(None.isEmpty)
//printing value of None as string
println(None.toString)
}
}
Output
输出量
List()
true
None
翻译自: https://www.includehelp.com/scala/nothing-and-null-types-in-scala.aspx
scala中查看类型