I'm making a Swing application that includes a JList and all the objects in the list are stored in a DefaultListModel. At the same time I need to pass the list to a method that receives as input a List. How can i convert a DefaultListModel to a List ?
This is the error i got:
The method computeSpending(List<Subscription>) in the type SubscriptionSpending is not applicable for the arguments (DefaultListModel<Subscription>)
Arrays.asList(defaultListModel.toArray());
Description:
DefaultListModelis not a subclass ofList. So it is not directly possible to pass that as aListargument. Instead you can change the parameter type toListModel<E>. Such as:Also, If you must need to pass the
DefaultListModel<Subscription>into aList, you can use: