The CAST operator converts a Java™ object to the user-defined type or Java class specified.
CAST( obj AS type )
The CAST() operator is required when you want to assign an object reference to variable defined with a user-defined type or Java class which requires narrowing reference conversion.
IMPORT JAVA java.lang.Object IMPORT JAVA java.lang.StringBuffer MAIN DEFINE sb1, sb2 java.lang.StringBuffer DEFINE o java.lang.Object LET sb1 = StringBuffer.create() LET o = sb1 -- Widening Reference Conversion does not need CAST() LET sb2 = CAST( o AS java.lang.StringBuffer ) -- Narrowing -- Reference Conversion needs CAST() END MAIN
IMPORT JAVA com.fourjs.fgl.lang.FglRecord TYPE mytype RECORD f1, f2 INTEGER END RECORD MAIN DEFINE r mytype DEFINE jr fgl.FglRecord LET jr = r LET r = CAST(jr AS mytype) -- This is denied: -- CAST(jr AS RECORD f1, f2 INTEGER END RECORD) END MAIN