How can I access a public static member of a Java class from ColdFusion?
In Java, static members are those which belongs to the class and you can access these members without instantiating the class. The static keyword can be used with methods, fields, classes (inner/nested), blocks.
Members of static classes can be accessed directly using the class name followed by a (.) and class member name. Class Members can be methods, fields, properties, or events. A static class can contain only the static members while a non-static class can contain static members.
A static method in Java is a method that is part of a class rather than an instance of that class. Every instance of a class has access to the method. Static methods have access to class variables (static variables) without using the class's object (instance). Only static data may be accessed by a static method.
To call a static method outside of the class that defines it we can use the class name such as Example. printMessage();.
You run the createObject but don't call the "init" before running the static method. For example:
<cfset systemObject = createObject("java", "java.lang.System") />
<cfoutput>#systemObject.currentTimeMillis()#</cfoutput>
In this case "currentTimeMillis()" is a static method of the System class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With