2.10 类型层次 Any、Unit、Nothing

本文介绍了Kotlin中的基本类型概念。根类型Any作为所有类的基类,提供toString(), hashCode()和equals()方法。Unit类型常用于无返回值的函数,可以省略显示返回。Nothing是最底层类型,表示没有任何值,常用于表示永不返回或可空类型的空引用。" 126264659,15028612,ZGC:Java未来低延迟GC的秘密解析,"['java', 'jvm', '后端', '算法']
摘要由CSDN通过智能技术生成

目录

         根类型Any

Unit类型:

Nothing类型:


根类型Any

Kotlin中所有的类都有一个共同的基类Any,如果类没有申明继承其他类的话,默认继承的就是Any。其实Kotlin中的Any就是对应Java中的java.lang.Object类型。

Any的源码如下:

public open class Any {
    /**
     * Indicates whether some other object is "equal to" this one. Implementations must fulfil the following
     * requirements:
     *
     * * Reflexive: for any non-null value `x`, `x.equals(x)` should return true.
     * * Symmetric: for any non-null values `x` and `y`, `x.equals(y)` should return true if and only if `y.equals(x)` returns true.
     * * Transitive:  for any non-null values `x`, `y`, and `z`, if `x.equals(y)` returns true and `y.equals(z)` returns true, then `x.equals(z)` should return true.
     * 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Alfred Gao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值