scala中查看类型_Scala中的虚无类型

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中查看类型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值