javaCast

Converts the data type of a CFML variable to pass as an argument to an overloaded method of a Java object.

javaCast(type, variable) → returns any

Argument Reference

type string
Required

The name of a Java primitive or a Java class name.
Values:
  • boolean
  • double
  • float
  • int
  • long
  • string
  • null
  • byte
  • bigdecimal
  • char
  • short

variable string
Required

A variable, Java object or array.

Compatibility

ColdFusion:

Version 4.5+ CF7+ Added null. CF8+ added bigdecimal, byte, char, short and for casting arrays.

Examples
Sample code invoking the javaCast function

Converts the number 180.0 degrees to radians using Java method: Math.toRadians(double degrees)

createObject("java", "java.lang.Math").toRadians( javaCast("double", 180.0) )

Expected Result: 3.14159265359

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub