I want to use `Contract` in my lib, to infer non-n...
# announcements
l
I want to use
Contract
in my lib, to infer non-nullability in a nullable value, and let users use it. However I don't want to force the user to use the compiler option. Is this possible? Or should I wait for contracts release?
s
That is why it is experimental. They need to opt in
l
I though that maybe my Lib can opt-in and users could use it without caring about the experimental features, as I'm providing the API for them
s
Not that I know the reason but I cannot see how your can shield the users from it. If the exprimental feature breaks your lib then their app is also broken right?
l
But the lib was already compiled, so the app shouldn't have any problem with it, right?
And then when I update the lib, it will be fixed when the user updates the version
r
AFAIK the Experimental annotations mean "The API might still change significantly", and not "This feature might break", so wanting to shield your users from it seems reasonable. And it is possible, by using the
@UseExperimental(ExperimentalContracts::class)
annotation instead of
@ExperimentalContracts
directly, iirc.
l
I tried to do that, but I got a "This class can only be used with compiler argument '-Xuse-experimenta=kotlin.Experimental"
r
Yeah, your library needs that compiler argument, but users of your libraries should be able to use your compiled library without the argument then.
l
Interesting. Seems what I needed. thanks!