How to instantiate/call java class with parameter

2019-06-01 09:58发布

问题:

For example, i have java class JRXlsExporter, if i instantiated that java from java my code is :

    JRXlsExporter myObject= new JRXlsExporter();

and from PHP become:

    $myObject = new Java("net.sf.jasperreports.engine.export.JRXlsExporter");

It works, but if i have java class with parameter, for example :

    JRXlsExporter myObject= new JRXlsExporter(param1,param2);

How to instantiate/call that java class from PHP ?

回答1:

Here is an example of how java.util.Date object is instantiated, with some constructor arguments:

$date = new Java("java.util.Date", 70, 9, 4);

Further, it says:

The new Java("java.util.Date", 70, 9, 4) call creates a new instance of the java.util.Date class using the java.util.Date(int year, int month, int day) constructor.

So, you could maybe try this:

$myObject = new Java("net.sf.jasperreports.engine.export.JRXlsExporter", param1, param2);