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.
In java there are Iterators
sample usage:
java.util.List matches = new java.util.ArrayList();
//stuff to add elements to list
Iterator it = matches.iterator();
while (it.hasNext())
{
RuleMatch m = (RuleMatch)it.next();
Console.WriteLine("Potential error:" + m.getMessage());
}
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<>();
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.