https://kotlinlang.org logo
#getting-started
Title
# getting-started
v

Vampire

07/25/2022, 11:43 AM
For "reasons" we have in our Gradle build logic
Copy code
import org.gradle.api.Action

inline fun <T> action(crossinline block: T.() -> Unit): Action<T> {
   return object : Action<T> {
      override fun execute(t: T) {
         t.run(block)
      }
   }
}
But updating Gradle to 7.5 and thus Kotlin to 1.6.10 now gives a compilation error (well warning, but we have
-Werror
) about wrong nullability:
Copy code
w: ...\buildSrc\src\main\kotlin\...\util\SamHelper.kt: (10, 7): Override 'fun execute(t: T): Unit' has incorrect nullability in its signature comparing with overridden 'fun execute(p0: T): Unit'
What is his problem suddenly and how do I mitigate it?
s

Sam

07/25/2022, 11:49 AM
In my IDE there’s a longer error:
Type parameter ‘T’ has nullable upper bound, so override has incorrect signature comparing with a base member with NotNull annotation. Please add a non-nullable upper bound (e.g. Any) to the type parameter. See https://kotlinlang.org/docs/generics.html#upper-bounds for more details
Seems like it’s suggesting
Copy code
inline fun <T: Any> action(crossinline block: T.() -> Unit): Action<T> {
v

Vampire

07/26/2022, 10:04 AM
Hm, thanks. I did not get that message anywhere. But I got the same solution from trial & error & guessing :-)
25 Views