Class 比较Kotlin类型和java类
除了JodDateTime之外,我正在尝试创建一个类似于这个问题的请求转换器 但是,我很难将传入的类型与Joda Date Time类进行比较Class 比较Kotlin类型和java类,class,types,kotlin,retrofit2,Class,Types,Kotlin,Retrofit2,除了JodDateTime之外,我正在尝试创建一个类似于这个问题的请求转换器 但是,我很难将传入的类型与Joda Date Time类进行比较 class JodaDateConverterFactory : Converter.Factory() { override fun stringConverter( type: Type?, annotations: Array<out Annotation>?, retrofit: Retro
class JodaDateConverterFactory : Converter.Factory() {
override fun stringConverter(
type: Type?, annotations: Array<out Annotation>?,
retrofit: Retrofit?
): Converter<*, String>? {
if (type is Class<*> && type==DateTime::class) {
return Converter<Any?, String> { value -> (value as DateTime).toString("yyyy-MM-dd") }
}
return null
}
}
class JodaDateConverterFactory:Converter.Factory(){
超控转换器(
类型:类型?,注释:数组?,
改装:改装?
):转换器{
if(类型为Class&&type==DateTime::Class){
返回转换器{value->(值为DateTime).toString(“yyyy-MM-dd”)}
}
返回空
}
}
类型==DateTime::类返回false
我可以看到该类型包含一个表示Joda日期时间的字符串,但我显然没有正确地比较它们
比较kotlin类型和java类的正确方法是什么
DateTime::class.java
要获取Java类型,请使用语法
DateTime::class.java
非常感谢我尝试了许多类似的事情,但错过了那一个!非常感谢我尝试了许多类似的事情,但错过了那一个!请注意,
类型是类&
是冗余的:如果(固定)比较成功,类型是类
肯定是真的。感谢Alexey,这很有用。请注意,类型是类&
是冗余的:如果(固定)比较成功,类型是类
肯定是真的。感谢Alexey,这很有用