I have this UserController with a GET users method.
public class UserController {
private final static Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final UserService userService;
public UserController(UserService userService) {
this.userService = userService;
}
@GetMapping
public List<User> getUsers() throws ResourceNotFoundException {
try {
return userService.getUsers();
} catch (Exception e) {
LOGGER.error(e.getMessage());
return ResponseEntity.internalServerError().build();
}
}
}
The problem is with the return type. Because I'm returning a list of users, I set that as the return type. But since it can also return a ResponseEntity, my IDE complains about it. The quick fix it offers is to set the return type to ResponseEntity but then of cause it will complain about the fact this method can return a List<User> type.
OR
How do I specify both possible return types?

