I’m trying to define a route using the new typesaf...
# compose
k
I’m trying to define a route using the new typesafe navigation. I can define something like this
Copy code
data class RouteA(val name: String?)
but not this
Copy code
data class RouteA(val name: Int?)
I’m getting
integer does not allow nullable values
- I assume this is correct but I was wondering why I can’t have optional Int arguments (this is 2.8.0-beta03)
i
Technically you could write your own
NavType
that supports nullable Ints, but, as the error message says, this is specifically and purposefully not supported - similarly for any primitive type. This aligns with the general Android API guidelines, which specifically don't encourage or want you to use nullable primitives (in part because they are hard to work with and in part because of the performance cost of the autoboxing it forces on each one)
k
Thanks Ian. Good to know the reason