Device virtualCapabilities Map is very loose

trickydee
Posts: 33
Joined: Fri Jul 17, 2015 8:58 am

Device virtualCapabilities Map is very loose

Postby trickydee » Thu Aug 18, 2016 5:45 pm

The virtualCapabilities on the Scala Device API seems to be very loose

Code: Select all

device.getVirtualCapabilities.toMap[Any,Any]
While I can understand having Any as the value type (although I think it's better if this can be a sealed set of types and not allow null) I think all keys in principle are Strings.

trickydee
Posts: 33
Joined: Fri Jul 17, 2015 8:58 am

Re: Device virtualCapabilities Map is very loose

Postby trickydee » Thu Aug 18, 2016 5:49 pm

Additionally, wasn't this API Map[String,String] before?

aaronp
Posts: 242
Joined: Wed Dec 09, 2015 12:39 pm

Re: Device virtualCapabilities Map is very loose

Postby aaronp » Fri Aug 19, 2016 10:57 am

Hi Stephen,

Thank you for letting us know. The change from [string,string] to [any,any] appear to have been made in order to meet compliance with the release of Scala 2.12-M4. I will discuss this with the engineers who worked on this project and will follow up with you when I have a more in-depth answer.

Thanks,

Aaron

trickydee
Posts: 33
Joined: Fri Jul 17, 2015 8:58 am

Re: Device virtualCapabilities Map is very loose

Postby trickydee » Sat Aug 20, 2016 10:09 am

Thank you,
To highlight one thing for example, it's no longer possible to simply take a capabilities map and append it the virtual capabilities capabilities ++ virtualCapabilities without getting an Map[Any,Any] which breaks our current code.
As a workaround we're mapping over the values and just casting asInstanceOf which would throw exceptions if things don't match up

Code: Select all

device.capabilities ++ device.virtualCapabilities.map { case (k, v) => (k.asInstanceOf[String], v.asInstanceOf[String]) }
In alternatives using collect and pattern matching is an option but that could fail silently.


Who is online

Users browsing this forum: No registered users and 9 guests