美文网首页kotlin学习笔记
Kotlin学习笔记-数据类型 数值类型转换(3)

Kotlin学习笔记-数据类型 数值类型转换(3)

作者: Rock__Lee | 来源:发表于2018-07-06 17:20 被阅读0次

java中数值类型 范围小的类型赋值给范围大的类型可以隐式转换
kotlin不可以

image.png
image.png
/**
 * Superclass for all platform classes representing numeric values.
 */
public abstract class Number {
    /**
     * Returns the value of this number as a [Double], which may involve rounding.
     */
    public abstract fun toDouble(): Double

    /**
     * Returns the value of this number as a [Float], which may involve rounding.
     */
    public abstract fun toFloat(): Float

    /**
     * Returns the value of this number as a [Long], which may involve rounding or truncation.
     */
    public abstract fun toLong(): Long

    /**
     * Returns the value of this number as an [Int], which may involve rounding or truncation.
     */
    public abstract fun toInt(): Int

    /**
     * Returns the [Char] with the numeric value equal to this number, truncated to 16 bits if appropriate.
     */
    public abstract fun toChar(): Char

    /**
     * Returns the value of this number as a [Short], which may involve rounding or truncation.
     */
    public abstract fun toShort(): Short

    /**
     * Returns the value of this number as a [Byte], which may involve rounding or truncation.
     */
    public abstract fun toByte(): Byte
}

相关文章

网友评论

    本文标题:Kotlin学习笔记-数据类型 数值类型转换(3)

    本文链接:https://www.haomeiwen.com/subject/opsbuftx.html