Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: java class with method named create()  (Read 7108 times)
Jos? V.
Posts: 58


« 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()
Rene S.
Four Js
Posts: 112


« Reply #1 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
  1. #4gl
  2. LET x = C.create()
acts like
Code
  1. //java
  2. x = new(C);

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
 



Jos? V.
Posts: 58


« Reply #2 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.
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines