简体   繁体   中英

How to convert List<Integer> to ArrayOfInt (not to be mistaken with int[])

I'm using a SOAP service written in WCF for my Java application and one of my service has a parameter of type int[] . When adding the service in Java, this int[] is converted to a type known as ArrayOfInt for serialization purposes. When I declare such type, it does not have any method to append to it. So, I tried to cast my List<Integer> to that type using:

List<Integer> Items = new ArrayList();
//Appending some integers to the list and checking if it has values 
// Then
com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfint Ai = (com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfint) Items;
org.datacontract.schemas._2004._07.inventorymanwcf.ArrayOfReceiptModel R = man.getBasicHttpBindingIManagement().sell(Ai, Login.Username);

Then the code caused an error :

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.microsoft.schemas._2003._10.serialization.arrays.ArrayOfint

My question is how handle that type, how to convert my list to an ArrayOfInt ?

If you refer to something like this it is obvious, that you cant create the array by itself. You could however override it: new ArrayOfint(){ @Override public List<Integer> getInt() { return Arrays.asList(insertIntarrayHere); }} new ArrayOfint(){ @Override public List<Integer> getInt() { return Arrays.asList(insertIntarrayHere); }} or new ArrayOfint(){ @Override public List<Integer> getInt() { return insertListHere; }} new ArrayOfint(){ @Override public List<Integer> getInt() { return insertListHere; }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM