Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access a public static member of a Java class from ColdFusion?

How can I access a public static member of a Java class from ColdFusion?

like image 594
Bialecki Avatar asked Oct 12 '08 20:10

Bialecki


People also ask

How will you access static member of a class in Java?

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.

How do you access members of a static class?

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.

How can we access static methods in Java?

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.

How do you access static methods outside the class?

To call a static method outside of the class that defines it we can use the class name such as Example. printMessage();.


1 Answers

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.

like image 170
Turnkey Avatar answered Sep 25 '22 02:09

Turnkey