Java Reference
In-Depth Information
Sequences are converted to an array of the Java type—for example, the String
sequence
var authors = [ "Clarke", "Connors", "Bruno" ];
is passed as a Java String[] array because authors is a sequence of String .
Likewise, the integer sequence
var numbers = [ 2, 4, 6, 8, 10 ];
can be applied to Java type, int [] or Integer[] . However, there is no auto-
matic conversion from a sequence of integer to other types, like double[] ,
float[] , long[] , and so on. To convert from one number type to the other, use a
for loop to convert to the desired type, and then use that result. For example, the
numbers integer sequence is converted to a sequence of type Double using a for
loop, as shown in the following example.
// returns Seq of Integer
var numbers = aJavaObject.callIntegerArray();
// convert to Sequence of Double
var dumbers = for (i in numbers) i.doubleValue();
anotherJavaObject.callDoubleArray( dumbers );
All other JavaFX object types not listed in the Tables 11.2 through 11.9 are
passed, unchanged, to and from the Java methods. For example, if you pass a
javafx.geometry.Point2D object to a Java method, it will still be a javafx
.geometry.Point2D object within the Java method. If the Java method returns a
Java object, like java.util.HashMap , it will still be a java.util.HashMap in
JavaFX.
Developers Warning: If you are passing a JavaFX object to Java that is not
automatically converted to a Java type as outlined in the preceding, it is important
that the Java code not manipulate it without using the JavaFX Reflection API.
Never manipulate a JavaFX object in any thread other than the main JavaFX
thread. Manipulating JavaFX objects outside of the main processing thread is not
safe . A way to make sure JavaFX object changes are executed on the main JavaFX
thread is presented at the end of this chapter.
When passing JavaFX objects to Java methods, interactions to those objects
should be made via the javafx.reflect package or via a JavaFX function.
Direct manipulation of the JavaFX variables within a JavaFX object must be
done via the JavaFX reflection framework. Another instance when the JavaFX
 
Search WWH ::




Custom Search