Haxe Java - How to check Java enums?

49 views
Skip to first unread message

TheHippo

unread,
Oct 25, 2013, 3:43:09 PM10/25/13
to haxe...@googlegroups.com
I've tried the Haxe Java target and so far I'm pretty impressed. (I need something done, but don't like writing Java, so I came back to Haxe.)

I need to wrap an existing Java library and currently using the "-java-lib" compiler flag to access the classes of this library. However a came across a Java enum and cannot figure out how to check / work with them.

The Java enum looks like this:

public enum LocationType
{
 ANY
, STATION, POI, ADDRESS
}

How do I check a variable against this enum?

TheHippo

unread,
Oct 25, 2013, 4:10:27 PM10/25/13
to haxe...@googlegroups.com
i.type is an instance of LocationType.

This does not work:
for (i in locations) {
 
switch (i.type) {
 
case LocationType.STATION:
   trace
("station");
 
default:
   
trace("other");
 
}
}


But this compiles and runs perfectly fine:

for (i in locations) untyped {
 
switch (i.type)  {
 
case LocationType.STATION:
   trace
("station");
 
default:
   trace
("other");
 
}
}

Cauê Waneck

unread,
Oct 25, 2013, 9:26:05 PM10/25/13
to haxe...@googlegroups.com
Java enums should be converted into Haxe enums when -java-lib is used.

What error does it show? Is LocationType an inner enum? Inner classes and enums have their name mangled.


2013/10/25 TheHippo <m...@thehippo.de>

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages