https://kotlinlang.org logo
Title
j

jamie-purchase

11/09/2017, 7:38 PM
Hi everyone - sorry if i'm not posting in the right place, i'm new here Jamie, live in Galway, Ireland - been experimenting with Kotlin for a short while now loved Java for years and still use it alot but loving the less-verbose and sexier Kotlin syntax anyway, I have a question about casting a value from a java method to a HashMap and i've exhausted my google-fu 😕 calling
getAttribute("something")
on an instance of
com.sun.net.httpserver.HttpHandler
and I need to cast it to
HashMap<String, Any>
but i'm unfamiliar with how to do that
j

jamie-purchase

11/09/2017, 7:40 PM
ah it can check at runtime? cool. thanks
p

pavel

11/09/2017, 7:41 PM
yep, more or less same as in Java
j

jamie-purchase

11/09/2017, 7:42 PM
okay so
val parameterMap = ex.getAttribute("parameters") as HashMap<String, Any>
isn't giving me any grief in the IDE anyway 🙂
p

pavel

11/09/2017, 7:44 PM
that would work in most cases, but will break down if the attribute is null or not there at all
as? is probably better
j

jamie-purchase

11/09/2017, 7:47 PM
it's a little weird still, thinking I want to not use nulls but i'm going to have to while i'm using java classes I think
do you have a karma/gratitude convention on this slack btw?
k

karelpeeters

11/09/2017, 7:51 PM
We usually react with 👍 here.
👍 1
j

jamie-purchase

11/09/2017, 7:53 PM
ah fair enough. only asking since the python and cfml slacks have a bot that lets you give awards to people and it keeps a score of who's most helpful and stuff.
thanks for the help @pavel
k

karelpeeters

11/09/2017, 7:57 PM
Let's leave measuring "usefulness" on stackoverflow 🙂.
🍻 1