Type Comparison Functions

The following functions for Type Comparison described here are:

instanceOf

Returns true if the value is of the specified type.

boolean instanceOf
 ( any  myValue ,
 any  myType  )
ParameterDescription

myValue

The value to evaluate. Can be of any type, even primitive types.

myType

Any type to evaluate against

Returns

true or false

Example - Using instanceOf

consume{
 if ( instanceOf( input, module1.type1 ) ) {
 	udrRoute( ( module1.type1 )input, "link_1" );
 } else if ( instanceOf( input, module2.type2 ) ) {
 	udrRoute( ( module2.type2 )input, "link_2" );
 } else {
 	// handle error case
 }
}

You can use variables of the types list and map in myValue, but the the contained types are not tested. In order to avoid confusion, it is recommended to always use any as a contained type in the myType argument.

Example - Using instanceOf with a contained type in the myType argument

consume { 
    // The contained types are int and string. 
    map<int, string> myMap = mapCreate(int, string); 
    list<string> myList = listCreate(string);
  
    // The expressions below are evaluated to true, 
    // since the contained types are not tested.
  
    if ( instanceOf( myMap, map<any,any>) ) { 
       debug("This is a map."); 
    }
  
    if ( instanceOf( myList, list<any>) ) { 
       debug("This is a list."); 
    } 
 }