如果本机 Java 方法返回值,则结果字段是可选的。
下列情况适用:
有关不匹配的长度的详细信息,请参阅赋值。
此自变量是字符串文字或类型为 CHAR、DBCHAR、MBCHAR、STRING 或 UNICODE 的变量。如果正在指定对象的标识,则该标识必须被强制类型转换为 objID,如稍后的示例所示。EGL 将从自变量值的开头和末尾除去单字节和双字节空格,其中,自变量值是区分大小写的。
在创建对象的标识之前,代码不能对该对象调用方法。后面的示例使用 java.lang.System.out 举例说明了这一点,其中,java.lang.System.out 引用 PrintStream 对象。
此自变量是字符串文字或类型为 CHAR、DBCHAR、MBCHAR、STRING 或 UNICODE 的变量。将从字符串的开头和末尾除去单字节和双字节空格,其中,字符串是区分大小写的。
可能需要进行强制类型转换,这在 Java 访问(系统字)中有所指定。
Java 类型转换规则生效。例如,即使将 short 传递给声明为 int 的方法参数,也不会发生错误。
为避免精度降低,使用 EGL 浮点变量来表示 Java 双精度,并使用 EGL smallfloat 变量来表示 Java 浮点。使用其它 EGL 类型中的某个类型可能导致值被四舍五入。
无论方法执行什么操作,调用程序中的内存区域都不会更改。
// call the constructor of the Java Date class and // assign the new object to the identifier "date". JavaLib.storeNew( (objId)"date", "java.util.Date"); // call the toString method of the new Date object // and assign the output (today's date) to the chaItem. // In the absence of the cast (objId), "date" // refers to a class rather than an object. chaItem = JavaLib.invoke( (objId)"date", "toString" ); // assign the standard output stream of the // Java System class to the identifier "systemOut". JavaLib.storeField( (objId)"systemOut", "java.lang.System", "out" ); // call the println method of the output // stream and print today's date. JavaLib.invoke( (objID)"systemOut", "println", chaItem ); // The use of "java.lang.System.out" as the first // argument in the previous line would not have been // valid, as the argument must either be a // an identifier already in the object space or a class // name. The argument cannot refer to a static field.
在处理 JavaLib.invoke 期间发生的错误会将 sysVar.errorCode 设置为下表中列示的值。
sysVar.errorCode 中的值 | 描述 |
---|---|
00001000 | 被调用方法抛出异常,或者作为类初始化的结果而抛出异常 |
00001001 | 对象为 null,或者指定的标识不在对象空间中 |
00001002 | 具有指定名称的公用方法、字段或类不存在或无法被装入 |
00001003 | EGL 基本类型与 Java 中期望的类型不匹配 |
00001004 | 方法返回 null、方法未返回值或者字段的值为 null |
00001005 | 返回的值与返回变量的类型不匹配 |
00001006 | 未能装入已强制类型转换为 null 的自变量的类 |
00001007 | 在尝试获取关于方法或字段的信息时抛出了 SecurityException 或 IllegalAccessException;或者尝试设置已被声明为最终字段的字段的值 |
00001009 | 必须指定标识而不是类名;方法或字段不是静态的 |
相关概念
相关任务
语法图