The stdlib has this function: ```public inline fun...
# announcements
m
The stdlib has this function:
Copy code
public inline fun <C, R> C.ifEmpty(defaultValue: () -> R): R where C : CharSequence, C : R =
    if (isEmpty()) defaultValue() else this
But when copy&pasting that code it doesn’t even compile!
Type parameter cannot have any other bounds if it’s bounded by another type parameter
Is it safe to silence that error? 😮
It seeeeeems to work
u
IIRC this error is reported because generic signatures on JVM do not support type parameters having more than one non-interface bound (side note: I wonder why it’s reported on other platforms though), and the resulting generic signature would probably be incorrect, which can trip up client code in Java and other JVM languages. For
ifEmpty
specifically, it seems OK to suppress it because the function is
inline
+
@InlineOnly
, so inaccessible from Java. In your case it might also be fine if you don’t have Java clients. If you do, you can prevent them from calling it by making it InlineOnly as well, however that leads to more error deprecations…
m
Thank you for the explanation. I’m absolutely fine with excluding other JVM clients 🙂 What do you mean by “more error deprecations”? That I have to
@Suppress
even more (internal access)?
u
Yes,
InlineOnly
is still internal to kotlin-stdlib
👌 1