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:

  1. Correct Import: Make sure you've imported the java.util.List interface correctly:

    import java.util.List;
    
  2. Method Return Type: Check if the ylYncfService.listByIds() method is actually returning a List<YlYncf> object. If it's returning a different type, you'll need to adjust the code to handle the correct return type.

  3. Constructor in YlYncf Class: Ensure that the YlYncf class has a default constructor or a constructor that accepts the parameters returned by ylYncfService.listByIds(). If it doesn't, add a suitable constructor to the YlYncf class.

  4. Constructor in Result Class: Verify that the Result class has a constructor that can accept a List<YlYncf> object. If not, modify the Result class's constructor to accept a List<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.

解决 'No primary or single unique constructor found for interface java.util.List' 错误

原文地址: https://www.cveoy.top/t/topic/qojw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录