Skip to main content

Type casting in compiled JavaFX

2 replies [Last post]
chrono_legionair
Offline
Joined: 2007-12-21
Points: 0

Hi,

I am using a HashMap to store a bunch of model objects (created in JavaFX) for later retrieval purposes.

<br />
attribute someMap = new HashMap();<br />
...<br />
someMap.put("id", someModel);<br />
...<br />

I then try to retrieve it as in normal Java, which works fine and returns me an Object. When I print out the Object to the console, it tells me that it is of type of someModel, however, when I try to invoke a method on it, I get the good old cannot find symbol error.

I used to be able to cast it in the traditional Java style in Interpreted JavaFX which no longer seems to work (I get a very long error basically saying the syntax is wrong)

<br />
var model = (SomeModel)someMap.get("id");<br />

And the following code gives me a incompatible type error, which makes sense.

<br />
var model: SomeModel = someMap.get("id");<br />

So, what is the new syntax (if there is one) or the correct way of casting types in Compiled JavaFX?

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tball
Offline
Joined: 2003-06-10
Points: 0

New syntax: someVariable [b]as[/b] theType, so "var model = someMap.get("id") as SomeModel;" should work.

chrono_legionair
Offline
Joined: 2007-12-21
Points: 0

Thanks, it works great.