List of expression elements / Data type operators |
The CAST operator converts a value or object to the type or class specified.
CAST( expr AS type )
The CAST() operator is required when you want to assign a value or object reference to variable defined with a type or class which requires narrowing reference conversion. This example shows code using the Java Interface facility of Genero BDL. When assigning a java.lang.StringBuffer reference to a java.lang.Object variable, widening reference conversion occurs and no CAST() operator is needed, but when assigning an java.lang.Object reference to a java.lang.StringBuffer variable, you must cast the object reference to a java.lang.StringBuffer.
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