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

Kevin Janvier Chinabalire

06/13/2018, 9:20 PM
Hey guys ... am trying to convert Any to an Object Class Any Idea ?
Copy code
fun bindview(pool:Any){
//want to convert 
}
I have my class
class Users(var name, var id)
m

malone

06/13/2018, 9:29 PM
Why do you need the conversion? In Kotlin, we don't have
Object
, so
Any
will work fine. If you have a Java API and should pass an
Object
instance, you can pass the
Any
as it is and the compiler will make it work.
k

Kevin Janvier Chinabalire

06/13/2018, 9:32 PM
What if i have an object class and i want to access some parameters inside ?
m

malone

06/13/2018, 9:35 PM
Are you trying to cast the
pool
as another type, let's say
Pool
?
You can use the safe-cast operator
as?
Copy code
(pool as? Pool)?.doSomething()
k

Kevin Janvier Chinabalire

06/13/2018, 9:36 PM
am trying val x: groupA = model as groupA
what about Any to an arraylist
?
e

edwardwongtl

06/14/2018, 3:51 AM
Just the same thing, use
as
k

Kevin Janvier Chinabalire

06/14/2018, 5:52 AM
No is not working ...
e

edwardwongtl

06/14/2018, 5:53 AM
You want casting or a actual conversion?