Tuesday, June 16, 2009

Java lists and JavaFX sequences

I play with JavaFX and found a strange behaviour.
The size of a Java list is not the same as the size of a JavaFX sequence !
Let me show what I mean.

With a simple Java class I build a list with 2 elements.

public class ListTestJava
{
public List getList()
{
List list = new ArrayList();
list.add("j one");
list.add("j two");
return list;
}
}
In Java FX, I instantiate the Java class, and ask for its size.
To compare I also build a JavaFX sequence.


var java = new ListTestJava;
var javaList :List =java.getList();
println(sizeof javaList);
for(j in javaList)
{
println("java value: {j}");
}

var count = ["fx one","fx two"];
println(sizeof count);
for(fx in count)
{
println("fx value: {fx}");
}


The result is:
1
java value: j one
java value: j two
2
fx value: fx one
fx value: fx two

Strange isn't it?
The reason for this behaviour is that the sizeof operator returns 1 on anything other than a sequence. A list is not a sequence.
Until now I don't know how to convert a Java list into a sequence!


No comments:

Post a Comment