`WHEN_ENUM_CAN_BE_NULL_IN_JAVA` is so annoying, th...
# getting-started
u
WHEN_ENUM_CAN_BE_NULL_IN_JAVA
is so annoying, then my enum is in kotlin
k
What?
u
whenever I
when
over my enum, which is defined in kotlin, i get that warning
k
Copy code
enum class Test { A, B }

val test = Test.A
when(test) {
    Test.A -> println("a")
    Test.B -> println("b")
}
doesn't give me any warnings.
u
hmmm youre right, ive narrowed it to rxjava
i.e. here it complains
Copy code
.subscribe {
                    when (it) {
                        ServiceCommand.START -> callServiceController.start()
                        ServiceCommand.STOP -> callServiceController.stop()
                        ServiceCommand.NO_OP -> Unit
                    }
                }
and subscribe() is java, it is right, bummer
k
Can't you do
it!!
?
u
yea I can, it even gives me
ServiceCommand!
as type
but why, if I wrap that method, and return nonnull, it still bitches
Copy code
fun <T : Any> Observable<T>.wrappedSubscribe(onNext: (T) -> Unit): Disposable {
    return subscribe(onNext)
}
k
Where does it give the warning? Strange thing is that I can't find anything about it on google.
u
on callsite, it makes "it" orange, when argument
k
Even with the wrapped one? Can you post a screenshot?
u
ive posted in the channel, because threads and images -_-
k
Why did you say it was
WHEN_ENUM_CAN_BE_NULL_IN JAVA
? And don't you want
wrappedSubscribe
?
u
yea, sorry that constant is what supresses the warning
and wrappedSubscribe is throwingSubscribe, i just happend to already use a extension that does some other thing, the problem is the same
it gives me unknown nullability type as lambda param, even though T : Any
ive posted a new screenshot, and with a regular method, not extension, to lessen your congnitive load
k
That's really strange. What happens when you explicitly specify
<ServiceCommand>
as the type parameter?
u
then its okay
maybe its because the observable is a java type, so that method level generic type is just a .. you know
i.e that T : Any is just in my code, and T is nullable in java, i dont know
k
Then that looks like a bug too me, try to get a minimal example working (with Java and Kotlin code) and post it on YouTrack.
In the meantime
it!!
should be fine simple smile
u
btw, so folks dont make fun of me 😄 T is nullable and only T: Any is nonnull right?
d
The code shown is not a bug. The value is coming from Java, so it is a platform type. The error message is exactly correct.
k
T
can be nullable depending on the callsite,
T: Any
is nonnull and
T: Any?
is certainly nullable.
@diesieben07 Sure, but the wrapper call shouldn't infer
T!
as the generic argument.
d
It doesn't. But if
Observable
is a java class, then even a
Obserable<T : Any>
(pseudo-syntax) can take nulls, because it is java code.
u
yea that is what I meant to say
d
And that is not a bug. Either you need to annotate your Java code or convert it to Kotlin
u
or maybe nest lambdas and have that !! ?
k
The lambda parameter of
wrappedSubscribe
receives a parameter of type
T
, which is inferred to be
ServiceCommand!
but it should have bound
T: Any
.
The bug is that
ServiceCommand! : Any
shouldn't work.
d
That is not what is happening.
I think.
And yes,
ServiceCommand! : Any
needs to work, otherwise platform types fall apart.
k
In the second screenshot, it literally says
it: ServiceCommand!
, and
it
has type
T
.
u
id agree if I were to just call subscribe, which is java method, that that warning is correct but id also assume that if i "repackage" the type in kotlin it should be back in kotlin nullaware type land