class somethins(ele:Any){
/*ele could be any type of View. TextView, ImageView, Editable and so on i would like do something like*/
var element=ele as typeOf(ele)
}
But how can i achieve that? Reflection wont work because of type Any
If you want to get the type and then work with this type statically, it is impossible in principle. Type is not known in compile time. If you want to do a dynamic dispatch, then use standard idiom:
when(element){
is A -> doSomethingWithA()
is B -> doSomethingWithB()
else -> error()
}
I wrote an animation class.
So that class should (e.G.) move givenElement.x=200f
But because i create my Views dynamically with different types (TextView, Buttons, ImageViews and so on)
i have pass type Any to my class (Because, could be Any)
But with “Any”, there is no ele.x (x is red and unassigned)
An i really hope that there is a way to not do the whole class for each Type
Actually View isn’t a class. It’s a given Type of kotlin. “TextView,Button,Editable,View” and so on. Basically everything can be catched from layout
View is the general one (one size fits all) if i had a good understanding of it
The only thing i know, that i don’t have to write a class View. So it seems to be a predefined class of google.
However. If im right, it does exactly what i need.
And as im usinig Kotlin for Android app developement only, should be my choice, right?