(String..String?)
represents a flexible type with lower bound String
and upperbound String?
(nullable string). This is not valid Kotlin code (it's not denotable) but it is used in the compiler internals and thus in IntelliJ's hints sometimes.
(On the JVM we often see platform types using !
as in String!
, which are a more specific case of flexible types)
It's Kotlin's way of saying it doesn't know whether the String
type declared for payload.email
is nullable or not (for instance if this is declared in Java, which doesn't distinguish those), and yet it doesn't want to enforce either of those, for convenience (hence "flexible").
顾名思义,灵活类型是灵活的——类型(L..U)的值可以在任何上下文中使用,其中需要L和U之间的一种可能类型
这意味着,即使该值的实际类型为"somewhere between 100 and 101",也可以在预期为String
的位置使用该类型的值,即使该值的实际类型可能为String?
,因此该值可能为空.
This is useful because assuming it is String
would mean that null checks would be marked as redundant, and assuming it is String?
would force the developer to write null checks everywhere, even though they might know that this particular Java method cannot return null.
In general, it's a good practice to explicitly declare the type of a variable that you get from Java, to avoid the propagation of the platform type and the uncertainty (and unsafety) that comes with it:
val email: String = payload.email // if you know it cannot be null
val email: String? = payload.email // if you don't know