Is there an easy way in Lucee 5 to implement an an...
# lucee
d
Is there an easy way in Lucee 5 to implement an anonymous abstract class? I'm doing some testing of some Java frameworks and wanted to test something w/out jumping through a bunch of hoops. I think the only way this can probably be done strictly in CFML is to build a string containing the Java, compile it and then load the bytes into the class loader. That's some ugly work and at the point it's just easy to go straight to java.
p
Just create your java, compile it and run it as a jar?
d
Yeah, that's definitely going to be easier than what I think you'd have to do in CFML. I was just curious if there was some syntax sugar I was missing. I've got a Java library I build for testing, so I might add something to that to do the work for future testing. I was just hoping there was some syntax sugar I was missing. I'm often testing Java libraries and when I'm trying to test quickly, it's much easier to stay in CFML than to create a Java project just to build some simple classes.
p
Well yea if I am following what you are requesting you can compile your basic classes directly as well…not sure how simple a full project would be
d
I was just curious for quick testing. When I can stay in one language/environment, it's just easier (well, as long as the language makes it easier). If I were going to production code, I'd implement this as a Java builder to create my anonymous abstract classes. However, at least for testing, not having to build a Java class avoids issues (like if I have to change the class, I need to restart the server, etc).
I was mainly just curious if there was a way I was not aware of
p
Copy code
<cfscript>
    javaCode = "
    package test;
    public abstract class AbstractTest {
        public abstract String getMessage();
    }

    public class ConcreteTest extends AbstractTest {
        @Override
        public String getMessage() {
            return \"Hello whatever here!\";
        }
    }";

    directoryCreate(expandPath("./test"), true);
    javaFile = expandPath("./test/ConcreteTest.java");
    fileWrite(javaFile, javaCode);

    // compile with javac
    javacPath = "/usr/bin/javac"; // or your windows path
    result = execute(javacPath & " " & javaFile);

    if (result) {
        // init your class now
        concreteTest = createObject("java", "test.ConcreteTest").init();
        writeOutput(concreteTest.getMessage());
    } else {
        writeOutput("Compilation failed.");
    }
</cfscript>
🙏 1
if that is a basic example, not certain exactly what you are attempting to do but this is what I was imagining as something basic to go off from
z
d
@zackster, thanks! I recall seeing this, which is why I was wondering if there might have been something in Lucee 5 I was missing. I"m really looking forward to testing 6 when I get a chance!
z
I think 5 has function type="java" too
d
I wonder if
CreateDynamicProxy()
could be used...
z
d
Thanks! Maybe some day I'll have time to go through the docs and add to each page when something was added, because I'm often wondering if something in the documentation works for the version I'm using.
Yeah, I add implementation dates for all new functions tags arguments and attributes which populates https://docs.lucee.org/reference/changelog.html but some of these aren't covered