0

I am currently making a CRUD application and findAll() is only accepting Iterable as output.

Can I use List imported from java.util.List instead of Iterable?

Currently, I am planning to use this code.

@Override
public List<Users> listUsers(Users users) {
    List<Users> listUsers = userRepository.findAll();
    return listUsers;
}

Users is my Entity and userRepository is my Repo.

I yield no error when I do this.

@Override
public Iterable<Users> listUsers(Users users) {
    Iterable<Users> listUsers = userRepository.findAll();
    return listUsers;
}

So, my question is, is it not possible to use List in this?

  • Well, I think we have the same case scenario but I tried adding an Override with FindAll() that returns List in my Repo then calls the function in my service but it still ask for an Iterable. – newProgHere Jan 26 '21 at 10:43
  • `List` is an `Iterable`. Why do you need a list? The only thing you are going to do is iterate over it and show results in the frontend, for that an `Iterable` is perfectly usable. – M. Deinum Jan 26 '21 at 11:01

0 Answers0