This functionality is available only for projects or scripts that use the Classic Agent.
Many Java methods return values of type java.lang.Object. In order to call such methods in Silk Test Classic, you must use invokeMethods() to call a method on the return object. Eventually, you must call a method that returns a 4Test-compatible value. However, you need to know the exact class of the java.lang.Object in order to know which methods are available for that object. Otherwise, you can only call java.lang.Object methods, which is a fairly limited list.
If your method returns a java.lang.Object value, you can use the following invokeMethods() call to return the name of the class of the return object:
STRING sClass = wObj.invokeMethods({"<method that returns java.lang.Object>", "getClass", "getName"}, {{<parameter list for the method of interest>}, {}, {}})
The above statement will call the following 3 Java methods:
Once you know the name of the class, you can call methods specific to that class. Preferably those methods will return a 4Test-compatible type. Otherwise, you will need to chain additional methods in the wObj.invokeMethods() call.
STRING sClass = wObj.invokeMethods({"<method that returns java.lang.Object>", "getClass", "getName"}, {{<parameter list for the method of interest>}, {}, {}}) ANYTYPE aProp1 ANYTYPE aProp2 switch sClass case "ClassA" aProp1 = wObj.invokeMethods({"<method that returns java.lang.Object>", "getClassAProperty1"}, {{<parameter list for the method of interest>}, {}}) aProp2 = wObj.invokeMethods({"<method that returns java.lang.Object>", "getClassAProperty2"}, {{<parameter list for the method of interest>}, {}}) case "ClassB" aProp1 = wObj.invokeMethods({"<method that returns java.lang.Object>", "getClassBProperty1"}, {{<parameter list for the method of interest>}, {}}) aProp2=wObj.invokeMethods({"<method that returns java.lang.Object>", "getClassBProperty2"}, {{<parameter list for the method of interest>}, {}}) default RaiseError (E_UNSUPPORTED, "java.lang.Object is of an unknown class: {sClass}")
toString() is a useful general method. It is a java.lang.Object method that returns a value of type java.lang.String and which translates to 4Test type STRING. You may be able to use toString() to return a value when you do not really understand what the previous method does. However, toString() may return a blank string, or the value may not make sense.