加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在Scala中初始化Array [BigInt]与Array [Int]

发布时间:2020-12-16 10:04:44 所属栏目:安全 来源:网络整理
导读:为什么Int类型的数组的条目初始化为0,但BigInt类型的数组的条目初始化为null? val a = new Array[Int](1)val b = new Array[BigInt](1)println(a.mkString())println(b.mkString()) 产量 0null 解决方法 根据 Int 的scaladoc: Instances of Int are not re
为什么Int类型的数组的条目初始化为0,但BigInt类型的数组的条目初始化为null?

val a = new Array[Int](1)
val b = new Array[BigInt](1)
println(a.mkString())
println(b.mkString())

产量

0
null

解决方法

根据 Int的scaladoc:

Instances of Int are not represented by an object in the underlying runtime system.

查看已编译的类文件,它确实显示Ints数组成为字节码中的int基元数组.并且int原语默认值为0.

0  iconst_1
1  newarray int [10]
3  astore_2 [a]
4  iconst_1
5  anewarray scala.math.BigInt [16]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读