https://kotlinlang.org logo
#announcements
Title
# announcements
t

tschuchort

09/29/2019, 10:34 PM
I have to override a Java method that uses an
@NonNull
annotation on a parameter even though documentation (and common sense) says that it can be null. If I make the same parameter nullable in my overriding Kotlin method, the compiler complains to me that I'm not overriding. But if I don't, then the function will crash at the hidden parameter assertion that is generated automatically. How do I tell the compiler "shut up, I know what to do"? Can I disable null-assertions for just this method?
k

Kirill Zhukov

09/29/2019, 11:05 PM
You have to override as non null. It seems though that your Java method should be
@Nullable
, so if have access to it you can fix that.
t

tschuchort

09/29/2019, 11:05 PM
I don't have access, that's the problem
But the compiler generates null checks for that argument, so if it's null it will crash
k

Kirill Zhukov

09/29/2019, 11:07 PM
So override as non null? Do you have to pass null to the API?
Is that some Android API btw?
t

tschuchort

09/29/2019, 11:09 PM
It's the Timber logging library
I'm not passing null to the library. It is passing null to me. So if I override with a non-nullable parameter, it will crash
k

Kirill Zhukov

09/29/2019, 11:15 PM
Timber should be in Kotlin now…
t

tschuchort

09/29/2019, 11:17 PM
Last release was 2018...
k

Kirill Zhukov

09/29/2019, 11:18 PM
yeah, it’s in Kotlin now
t

tschuchort

09/29/2019, 11:18 PM
Not released though. But apparently they changed it so the argument is actually never null. Just the docs are outdated
Annoyingly there was a PR 2 years ago to fix this but never got merged due to bikeshedding 😑
k

Kirill Zhukov

09/29/2019, 11:21 PM
4.7.1
is the latest released version, it has Timber written in Kotlin.
What’s the specific API?
t

tschuchort

09/29/2019, 11:22 PM
Timber.Tree.log(int priority, @Nullable String tag, @NotNull String message, @Nullable Throwable t)
My dependency in the build.gradle file is 4.7.1 and that file is still Java when I go to it
🤔 1
When I browse the repo at 4.7.1 tag it's still Java too. The release is just too old to include the Kotlin port it seems
k

Kirill Zhukov

09/29/2019, 11:29 PM
Ugh, you are right, it’s not released yet 😕
t

tjohnn

09/30/2019, 6:13 AM
The owner of timber is in this channel.. probably he could find time to help. @jw
t

tschuchort

09/30/2019, 10:34 AM
If only the docs are outdated then there's no need to update it right now.
3 Views