getClass() Method for Components
getClass() Method for Components
In Lucee, components that implement Java interfaces can use the getClass()
method to obtain the Java class representation. This method automatically creates (if needed) a dynamic proxy and returns the proxy's class, enabling seamless Java interoperability without explicit proxy creation.
Available since Lucee 7.0
Basic Usage
When called on a component that implements Java interfaces, getClass()
returns the Java class of the dynamic proxy:
mymap = new component implements="java:java.util.Map" {
// component implementation
};
classInfo = mymap.getClass(); // Returns proxy class
dump(classInfo);
This is equivalent to the more verbose:
classInfo = createDynamicProxy(mymap).getClass();
Method Resolution Order
The getClass()
method follows a specific resolution order:
- Custom Function: If the component defines a function named "getClass", that function is called
- Property Getter: If the component has a property named "class" with
accessor=true
, the getter is used - Default Behavior: Otherwise, a dynamic proxy is created and
proxy.getClass()
is returned
Requirements
- The component must implement at least one Java interface
- The method only applies to components, not regular objects
Use Cases
This feature is particularly useful for:
- Java library integration where class information is needed
- Reflection operations on component proxies
- Framework development requiring class metadata
- Simplified Java interoperability code