Search code examples
c#ikvm

Using java.util.List in C# with IKVM


I'm trying to make a call to a java application using a C# client. The object that is sent is of type java.util.List. I've added the required IKVM assemblies to my C# project. I'm just unsure how I should instantiate the List object. As it's just on interface I can't just create a new instance of it.

 java.util.List myList = new java.util.List();

Could someone provide me help on using this? Thanks in advance.


Solution

  • As we know that the type java.util.List is an interface (and it is not a class type so we can't instantiate). You need to use the any class type which is an implementation of java.util.List.

    java.util.List myList = new java.util.ArrayList();
    

    Or even better to use type parameter:

    java.util.List<Integer> myList = new java.util.ArrayList<>();