[英]what is the java equivalent of <?,?> in Kotlin?
here is my method这是我的方法
void login(Event<?, ?> event);
I am wondering how it should be in Kotlin我想知道它应该如何在 Kotlin
In Kotlin wildcard operator is *
.在 Kotlin 通配符运算符是
*
。 It instructs the compiler that it is unknown but once it got known there will be no other object of another type.它指示编译器它是未知的,但一旦它被知道,就不会再有其他类型的 object。
Replacement of更换
Java -> Kotlin Java -> Kotlin
<?>
-> <*>
<?>
-> <*>
Object
-> Any?
Object
-> 有Any?
<? extends A>
<? extends A>
-> <out A?>
<? extends A>
-> <out A?>
<? super A>
<? super A>
-> <in A?>
<? super A>
-> <in A?>
Here question mark (
?
) above means the field can be nullable, in java null and non-null are same but in Kotlin to accept null we need to explicitly mark it nullable.Here question mark (
?
) above means the field can be nullable, in java null and non-null are same but in Kotlin to accept null we need to explicitly mark it nullable.
fun login(event: Event<*, *>?)
Star projection , denoted by the *
character.星形投影,用
*
字符表示。 Sometimes you want to say that you know nothing about the type argument, but still want to use it in a safe way.有时您想说您对类型参数一无所知,但仍想以安全的方式使用它。 The safe way here is to define such a projection of the GENERIC TYPE .
这里安全的方法是定义GENERIC TYPE的这种投影。
Read official guideline about Star-projection
Kotlin syntax.阅读有关
Star-projection
Kotlin 语法的官方指南。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.