I often use UUID.randomUUID()
. Type inferred by kotlin is UUID!
. is there any way to tell kotlin that return type of this specific method is UUID
and is always non null? or do i have to do everywhere UUID.randomUUID()!!
or implement my own method?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Kotlin does not force you to use
!!
on platform types. If the return value of the function from Java does not have nullability annotations@NotNull
or@Nullable
, it can be treated as either nullable or non-null:If you treat it as an non-null type but it is actually null, exception will be thrown.
If you explicitly declare the types, it should declare them non-nullable instead of as a platform type.
I do this with a function to make things a bit easier. By declaring the return type, it has the same effect:
Or as an extension: