CAST

The CAST operator converts a value or object to the type or class specified.

Syntax

CAST( expr AS type )
  1. expr can be any expression supported by the language.
  2. type is a structured user defined type or a Java™ class.

Usage

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