java中数值类型 范围小的类型赋值给范围大的类型可以隐式转换
kotlin中不可以
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
}
网友评论