Hello I have an array of functions that accepts a ...
# announcements
r
Hello I have an array of functions that accepts a View argument:
Copy code
val manyFunctions: ArrayList<(View) -> Unit> = arrayListOf(
    {layout: TextView -> Unit}
)
But that don't work cos
TextView
is not exactly
View
though it subclasses it.
d
Change
View
to
out View
or
in View
. I don't remember which will work but one should.
d
Yes, your function does not accept
View
, it only accepts
TextView
. How do you intend to even call these functions? You can't. @Dominaezzz That does not work in a function type (it's not really useful, the parameters are always
in
, the return type is always
out
).
d
Oh true.
r
Why can't you call them? Functions are meant to be called.
d
What argument would you pass?
r
An instance of a View type
d
If you had a (theoretical)
{ foo: out Thing -> Unit }
there is no way to call it, since you cannot know what it's actual parameter is.
r
Ok I think I'm back to the same discussion I had with Shawn yesterday
d
If you pass on anything that isn't a
TextView
, you'll get a ClassCastException or similar. Given it compiles.
d
It will only compile with an "unchecked cast" warning
r
Thanks guys for the clues, I think I know where to go.
I hit a wall again, so instead of doing:
Copy code
ArrayList<(View) -> Unit>
I tried to do:
Copy code
ArrayList<((Context) -> View) -> Unit>
But that's a syntax error
I basically substituted
View
for
(Context) -> View
.
oh wait, it works? must be bracket problems
nevermind it doesn't make sense anyway