Skip to content

Reasons to bound Value for non-null values only? #55

Answered by arkivanov
Prototik asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the question! This was already discussed a while ago. But it's good to repeat it here as well. Here is the copy of the original answer.

This is by design, due to how generics are exported to Swift. If we define it as Value<T>, then a non-null type (e.g. Value<String>) will be still nullable in Swift.

For the same reason they both are classes, and not interfaces. Because generics for an interface cannot be exported to Swift.

You can workaround nullable types by using something like data class Optional<T : Any>(val value: T?).

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by Prototik
Comment options

You must be logged in to vote
1 reply
@arkivanov
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #54 on March 22, 2022 13:25.