IBM Support

webMethods Knowlegebase : Cannot cast an array of interfaces to an array of objects (1778768)

Troubleshooting


Problem

The problem here has been found that we do not like casting a full array of a cross-compiled Java interface into an array of generic Java Objects.

We are casting an array of Java Action[] objects into Object[]. Although we can cast arrays of implementations, we cannot cast without exception when the Array type is of a Java interface. This is why making a new Object[] array and assigning each index to match with the Action[] array, with the types cast individually as Java Object works - because we are dealing with specific implementations in each case. Similarly, an array of an implementation of Action (e.g. DefaultAction?[]) would cast fine to Object[] however casting an array of Java interfaces to Object[] will cause the C# system to throw a ClassCastException, presumably because the interface itself does not explicitly extend Java Object and thus cannot be cast.

Example code:

Java:

public interface Thing {

}

public class DefaultThing implements Thing {

}

C# referencing the cross compiled Java:

Thing[] collection = new Thing[] { new DefaultThing(), new DefaultThing() };

DefaultThing[] collectionImpl = new DefaultThing[] { new DefaultThing(), new DefaultThing() };

JObject[] castSuccess = (JObject[])collectionImpl; // This should be fine

JObject[] castFail = (JObject[])collection; // This should throw a System.ClassCastException

Document Location

Worldwide

[{"Line of Business":{"code":"LOB76","label":"Data Platform"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSAWP1J","label":"IBM webMethods BPM"},"ARM Category":[{"code":"a8mKe00000000AQIAY","label":"webMethods Mobile Designer (WWW)"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Windows 8 Professional Edts"}],"Version":"9.7"}]

Log InLog in to view more of this document

This document has the abstract of a technical article that is available to authorized users once you have logged on. Please use Log in button above to access the full document. After log in, if you do not have the right authorization for this document, there will be instructions on what to do next.

Document Information

Modified date:
19 March 2025

UID

ibm17191229