Status/Resolution/Reason: To Fix//Investigate
Reporter/Name(from Bugbase): Luis Majano / Luis Majano ()
Created: 02/22/2018
Components: Language, Java Integration
Versions: 2018
Failure Type: Others
Found In Build/Fixed In Build: /
Priority/Frequency: Normal /
Locale/System: / iOS All
Vote Count: 8
Doing modern Java integration sucks at this point with CFML. No easy way to class load dynamically, extend java objects and implement java objects from CFCs. Please look at my other tickets on extending java classess and implementing them from CFCs.
This one is for java lambdas. This is in much much more usage in modern Java APIs and integrating them with CFML is horrible and cumbersome.
I propose a CF -> Java lambda translation. First, lambdas need to be implemented first so please address this, lucee has them already.
- Ability to create Java Lambdas as proxies so we can pass them into Java. This should be dynamic, meaning if we define a lambda and pass it to the java function the type inference should kick in from Java.
Let's look at an example, here is a Java Interface:
{code:java}
java
// Interface
public interface StateChangeListener {
public void onStateChange(State oldState, State newState);
}
// Class accepting the interface
public class StateOwner {
public void addStateListener( StateChangeListener listener) { ... }
}
{code}
Right now, we would have to create a CFC and use dynamic proxy in order to satisfy this interface. Cumbersome for a single function interface. In Java I would do two things:
{code:java}
**Inline Interface**
java
stateOwner.addStateListener( new StateChangeListener() {
public void onStateChange(State oldState, State newState) {
// do something with the old and new state.
}
} );
{code}
**Lambda**
{code:java}
java
StateOwner stateOwner = new StateOwner();
stateOwner.addStateListener(
( oldState, newState ) -> System.out.println( "State changed" )
);
{code}
So why not do this automatically cast a CFML lambda to a Java Lambda.
cfml
{code:java}
stateOwner = new java:StateOwner();
stateOwner.addStateListener(
( oldState, newState ) => systemOutput( "State changed" )
);
{code}
As you can see, they would be a CFML lambda tht satisfies the interface.
Attachments:
Comments: