解决 'No primary or single unique constructor found for interface java.util.List' 错误
The error message 'No primary or single unique constructor found for interface java.util.List' indicates that there's a problem with how you're trying to use the java.util.List interface. Here's a breakdown of the error and potential solutions:
Understanding the Error:
The java.util.List interface is an abstract data structure. It doesn't have a constructor you can directly call to create an instance. You need to use concrete implementations of the List interface, like ArrayList, LinkedList, etc. The error message is telling you that there's no way to create an instance of the List interface directly.
Troubleshooting Steps:
-
Correct Import: Make sure you've imported the
java.util.Listinterface correctly:import java.util.List; -
Method Return Type: Check if the
ylYncfService.listByIds()method is actually returning aList<YlYncf>object. If it's returning a different type, you'll need to adjust the code to handle the correct return type. -
Constructor in YlYncf Class: Ensure that the
YlYncfclass has a default constructor or a constructor that accepts the parameters returned byylYncfService.listByIds(). If it doesn't, add a suitable constructor to theYlYncfclass. -
Constructor in Result Class: Verify that the
Resultclass has a constructor that can accept aList<YlYncf>object. If not, modify theResultclass's constructor to accept aList<YlYncf>.
Example:
Let's assume you have an ArrayList implementation of the List interface, and the Result class has a constructor that accepts a List object:
public Result<?> cflistByIds(List<Integer> ids) {
List<YlYncf> list = new ArrayList<>(); // Create an ArrayList
if (ids != null && ids.size() > 1) {
list = ylYncfService.listByIds(ids);
}
return Result.ok(list); // Pass the ArrayList to the Result constructor
}
By addressing these potential issues, you should be able to resolve the 'No primary or single unique constructor found for interface java.util.List' error.
原文地址: https://www.cveoy.top/t/topic/qojw 著作权归作者所有。请勿转载和采集!