Title: java class with method named create() Post by: Jos? V. on March 30, 2022, 11:40:48 am I'm using the java interface and one class from the framework I'm trying to use has a static method called create().
So when I call this method from 4gl, fglcomp and fglrun assume I want to call the builder method. How can I call the actual method from the class and not constructor? What I'm doing: JcvClass.java(just an example): Quote class JcvClass { public JcvClass(){} public static String create(){ return "new string"; } } and then in 4GL: Quote IMPORT JAVA JcvClass main display JcvClass.create() end main This code calls JcvClass.JcvClass() and not JcvClass.create() Title: Re: java class with method named create() Post by: Rene S. on May 17, 2022, 08:03:47 am Hello,
this is a know limitation/issue: if fglcomp sees C.create() where C is a class name, then the compiler assumes this is a call to the constructor. Code acts like Code
This implies: it is not possible to call a static Java method named create from 4gl. Unfortunately: there is no workaround. There is now way to fix without breaking any existing code. Decades after the 1sh implementation of "call java from 4gl" I am asking myself, why we have used the name create. We should have used the name new. The symbol new is a reserved word in Java, a method can not be named new. Too late. The compiler should raise a warning if a java class implements a method named create "conflicting" withe a constructor. The compiler could 1st) lookup for a constructor - for backward compatibility - next lookup for a method. This would still fail if both, constructor and method exist. Rene Title: Re: java class with method named create() Post by: Jos? V. on May 17, 2022, 10:06:26 am Thank you for the reply/explanation Rene.
That was our fear. We will try to make a wrapper class to call the framework in order to try and workaround the issue. |