I'm trying to create an instance of: java.awt.geom.Point2D.Double in coldfusion:
Point2D.Double is a nested class inside of the abstract class Point2D. I have tried to instantiate the class, but get, "This fails because Coldfusion cannot find the class." And which does not work because Point2D is an abstract class and there is not a public constructor on which you can call PointClass.init(x,y). Right now, I've resorted to making my own Point class that wraps the Point2D.Double class so that I can instantiate it in Coldfusion. I don't think this is ideal and am looking for ideas about how to directly create a Point2D.Double class in Coldfusion. I'm also using Coldfusion 8.
Working with nested Java classes in ColdFusion is easy, as long as you know the secret hand shake (which is kept very hush hush). If you try to instantiate the nested classes using dot-notation in ColdFusion, as you have tried:
<!--- Create the point object. ---> <cfset objPoint = CreateObject( "java", "java.awt.geom.Point2D.Double" ).Init( JavaCast( "double", 5 ), JavaCast( "double", 10 ) ) />
... you will get the following error:
Object Instantiation Exception. Class not found: java.awt.geom.Point2D.Double
The trick here is that when referring nested classes in the class path, you have to use the dollar sign ($) rather than the dot (.):
Knowing that, when we run this code:
<!--- Create the point object. ---> <cfset objPoint = CreateObject( "java", "java.awt.geom.Point2D$Double" ).Init( JavaCast( "double", 5 ), JavaCast( "double", 10 ) ) /> <!--- Output the point string. ---> <cfdump var="#objPoint.ToString()#" />
... we get the following output:
... which indicates that the Point class was proparly instantiated and utilized. Hope that helps.
Want to use code from this post? Check out the license.