在 Kotlin 中将 java 长值解析为字符串
Parsing java long value to String in Kotlin
我有一个由 ApolloClient 框架生成的 Java class。
一般来说,我所有的代码都是用 Kotlin 写的。
Java 中的 long 值在 Kotlin 中无法解析为 String( 或 Long) 存在问题。
这是代码片段:
(Java代码)
CountryCode.java
public class CountryCode {
private long code;
public long getCode(){
return code;
}
}
(Kotlin 代码)
CountryUseCase.kt
fun getCode(countryCode: CountryCode) : String {
return countryCode.getCode() // We have to convert long to String here !!!
}
如何在 Kotlin class 中将 Java class 的长值转换为字符串?
Represents a 64-bit signed integer. On the JVM, non-nullable values of this type are represented as values of the primitive type long
.
而 Long?
将表示为 java.lang.Long
。
您还会在 documentation 中找到一个 toString()
方法。
我有一个由 ApolloClient 框架生成的 Java class。
一般来说,我所有的代码都是用 Kotlin 写的。
Java 中的 long 值在 Kotlin 中无法解析为 String( 或 Long) 存在问题。
这是代码片段:
(Java代码)
CountryCode.java
public class CountryCode {
private long code;
public long getCode(){
return code;
}
}
(Kotlin 代码)
CountryUseCase.kt
fun getCode(countryCode: CountryCode) : String {
return countryCode.getCode() // We have to convert long to String here !!!
}
如何在 Kotlin class 中将 Java class 的长值转换为字符串?
Represents a 64-bit signed integer. On the JVM, non-nullable values of this type are represented as values of the primitive type
long
.
而 Long?
将表示为 java.lang.Long
。
您还会在 documentation 中找到一个 toString()
方法。