https://kotlinlang.org logo
#android
Title
# android
d

dan.the.man

11/26/2018, 7:11 PM
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

Jake

11/26/2018, 7:12 PM
I believe you wan to use
T
instead. I'll check into that.
d

dan.the.man

11/26/2018, 7:13 PM
The letters shouldn't matter for generics? I have a half dozen different ones
j

Jake

11/26/2018, 7:16 PM
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

dan.the.man

11/26/2018, 7:19 PM
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

Jake

11/26/2018, 7:27 PM
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

dan.the.man

11/26/2018, 7:28 PM
That would still compile though.
I
is a subclass of
Any
so it should work
j

Jake

11/26/2018, 7:28 PM
Sorry, I'm looking at it backwards.
You're passing
I
into an
Any
parameter not
Any
to an
I
parameter
d

dan.the.man

11/26/2018, 7:29 PM
Yes
j

Jake

11/26/2018, 7:29 PM
Interesting.
Does it give you any specific error response?
aside from the
expected
vs
actual
d

dan.the.man

11/26/2018, 7:34 PM
Nope
j

Jake

11/26/2018, 7:40 PM
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

ienoobong

11/27/2018, 5:42 AM
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

ahulyk

11/27/2018, 9:33 AM
you can use *
r

rkeazor

11/27/2018, 6:03 PM
Any isn’t a generic , its a Type. so it would <T: Any>
Your probably thinking of Star Projection in kotlin