How can I convert this code to kotlin? ``` publi...
# announcements
p
How can I convert this code to kotlin?
Copy code
public static JsonAdapter<?> create(Class<?> rawType) {
    return new SafeEnumJsonAdapter<>((Class<? extends Enum>) rawType).nullSafe();
  }
d
Copy code
fun create(rawType: Class<*>): JsonAdapter<*> {
    @Suppress("UNCHECKED_CAST")
    return SafeEnumJsonAdapter(rawType as Class<Nothing>)
}
p
Can you explain this? What's
Class<Nothing>
d
@Suppress("UNCHECKED_CAST")
fun create(rawType: Class<*>): JsonAdapter<*> {
return SafeEnumJsonAdapter(rawType as Class<out Enum<*>>).nullSafe()
}
d
Nothing
is a type that is a subtype of every other type.
So
Class<Nothing>
is assignable to any other
Class<T>
, whatever `T`might be
p
@Dipali Nope; "Can't infer type T"
d
So
Class<Nothing>
is assignable to
Class<E extends Enum<E>>
p
Thanks, now I'm understanding it slightly better ^^