How do I pass a value of a non-null type to a met...
# announcements
b
How do I pass a value of a non-null type to a method that accepts that type but as a nullable parameter? The other way around makes sense to safe-check, but if I'm giving you a non-nullable type as a parameter and you can accept nullable types, there's gotta be a way it can be taken
s
This should just work normally - you can definitely pass, for example
String
to a function that takes
String?
you should also be able to pass a non-null generic type to a function that takes a nullable one
Unless you mean you’re trying to pass a
Column<Int>
to a function that takes
Column<Int?>
b
The latter
Sorry, not quite, Column<Int>?
s
If that’s the case, you should just be able to use it intuitively
b
Actually so my full type is Column<EntityID<Int>?>
s
oh
b
So the nullable part is the EntityID inside of the Column, that's what it doesn't like
k
👆 1
b
Ok thanks I'll take a look
k
Foo<X>
is not necessarily a subtype of
Foo<X?>
, it can be the other way around or not at all.
b
Gotcha, ok yeah that kinda sucks because I have some helper methods that encapsulate common logic and I basically have to create a copy of the same method with a different name and it does the exact same thing just because of the type issue
s
you might be able to do what you want with the correct type projections, though
b
I'll definitely try
k
Yeah it doesn't "suck", it's the typesystem forcing you to make your code more correct!
b
Agreed haha I definitely like it better than the alternative