Does `Any` not work for any generic? I have code t...
# android
d
Does
Any
not work for any generic? I have code that's
Expected : <http://Request.POST|Request.POST><Any, O>
Actual: <http://Request.POST|Request.POST><I, O>
and that's causing me some issues
j
I believe you wan to use
T
instead. I'll check into that.
d
The letters shouldn't matter for generics? I have a half dozen different ones
j
You're right. Letters don't matter. I misunderstood your issue.
I believe the problem is that
Any
allows for more than one type where a generic of type
T
or
I
or whatever you choose constrains it to any one type.
d
Isn't
Any
the equivilent to Java's
Object
Where everything extends it?
So generic
I
should be a subclass of it
Even explicitly putting
I : Any
it's failing
j
Well that I think is the issue.
I != Any
because an array of type
I
would be an array of one type explicitly. i.e.
arrayOf<String>("a","b","c")
where
Any
could be
arrayOf<Any>(1, "Blue", SomeObject, ...)
d
That would still compile though.
I
is a subclass of
Any
so it should work
j
Sorry, I'm looking at it backwards.
You're passing
I
into an
Any
parameter not
Any
to an
I
parameter
d
Yes
j
Interesting.
Does it give you any specific error response?
aside from the
expected
vs
actual
d
Nope
j
Can you post the call you're making that causes the error? I think you do need to cast it
as Any
but your comment
: Any
is making me wonder what's going on.
I would imagine you would have something like:
Copy code
val genericVal = getGeneric()
val data = getData()
<http://Request.Post|Request.Post><genericVal as Any, data>()
and not
<http://Request.Post|Request.Post><genericVal : Any, data>()
i
I think
Any
in your case is the type parameter, equivalent to
T
or anything you want to call it. Can you post the method signature of `POST
a
you can use *
r
Any isn’t a generic , its a Type. so it would <T: Any>
Your probably thinking of Star Projection in kotlin