Tag: int

Kotlin有一个标准的方式来将一个数字格式化为一个英文序数?

在Swift中,我可以这样做: let ordinalFormatter = NumberFormatter() ordinalFormatter.numberStyle = .ordinal print(ordinalFormatter.string(from: NSNumber(value: 3))) // 3rd 但是我没有办法在Kotlin那么容易地做到这一点。 有没有这样的方式,或者我将不得不使用第三方库或写我自己的?

Kotlin编译错误:使用提供的参数不能调用以下函数

我正在尝试学习Kotlin,并在kotlin中创建了一个简单的类,它在构造函数中接受两个int,并添加它们。 这些int可以为null。 I am receiving compilation error as: None of the following functions can be called with the arguments supplied: public final operator fun plus(other: Byte): Int defined in kotlin.Int public final operator fun plus(other: Double): Double defined in kotlin.Int public final operator fun plus(other: Float): Float defined in kotlin.Int public final operator fun plus(other: […]

Kotlin字符串到Int数组

我正在寻找最有效的方式来转换一个字符串 “[1,2,3,4,5]” 到Kotlin中的Int [1,2,3,4,5]数组

Kotlin编译错误:使用提供的参数不能调用以下函数

我正在尝试学习Kotlin,并在kotlin中创建了一个简单的类,它在构造函数中接受两个int,并添加它们。 这些int可以为null。 I am receiving compilation error as: None of the following functions can be called with the arguments supplied: public final operator fun plus(other: Byte): Int defined in kotlin.Int public final operator fun plus(other: Double): Double defined in kotlin.Int public final operator fun plus(other: Float): Float defined in kotlin.Int public final operator fun plus(other: […]

如何将Int转换为Kotlin中的字符串

我有以下代码试图将一个Int转换为Kotlin中的字符串(在Android Studio中)没有任何明显的方式工作,但我不知道为什么或如何将Int转换为字符串: processButton.setOnClickListener { var intNo = inputText.text as Int intNo *= 2 outputText.text = intNo as String // error = "required editable" outputText.text = intNo.toString() // err: type mismatch outputText.text = Int.toString(intNo) // type mismatch reqd editable outputText.text = "What is going on?" // type mismatch reqd editable }

Kotlin数据类型是由原始的还是非原始的Java数据类型构建的?

我是Kotlin的新手,正在玩弄数据类型。 我采取了一个Int类型,然后尝试把它作为一个Double通过说num as Double ,一个在java中有效的调用(非语法上,但你得到的重点)。 然而,这失败了,说诠释不能转换为双。 我假设这是因为它是建立在整数类而不是原始的int数据类型。 我是否正确,什么是最有效的投资价值的方式? 有一个.toDouble()函数,但是这似乎是低效和笨拙的。

kotlin int盒装身份

在我们的文档中 请注意,装箱数字不会保留身份 但接下来的例子给出了不同的结果 val number1 = 127 val b1 : Int? = number1 val b2 : Int? = number1 print(b1 === b2) // this prints true val number2 = 128 val c1 : Int? = number2 val c2 : Int? = number2 print(c1 === c2) // this prints false 在大于127的数字按预期工作,但不在128(8位)以上时,为什么?

Kotlin有一个标准的方式来将一个数字格式化为一个英文序数?

在Swift中,我可以这样做: let ordinalFormatter = NumberFormatter() ordinalFormatter.numberStyle = .ordinal print(ordinalFormatter.string(from: NSNumber(value: 3))) // 3rd 但是我没有办法在Kotlin那么容易地做到这一点。 有没有这样的方式,或者我将不得不使用第三方库或写我自己的?

Kotlin数据类Gson序列化问题

林有点困惑我的kotlin类没有按预期工作: 用于检查更新信息的数据类: data class UpdateInfo constructor(//kotlin class val description: String, val force: Int, val platform: String, val title: String, val url: String, @SerializedName("version") val versionCode: Int = 0 ) : Serializable { val isForceUpdate = force == 1 } 还用于解码对象形式JSON的util: public class JsonUtil {//java class private static final Gson gson; static { BooleanAdapter booleanAdapter = […]