lundi 30 janvier 2017

Returning from an if block Java

I have this trivial piece of code :

public ModelAndView postLoginPage(@ModelAttribute("user") User user, ModelMap model,
                                      HttpServletRequest req, HttpServletResponse res) {

        if (user != null) {
            logger.log(Level.INFO, "\n\n [*][*][*][*][*] user not null ");
            if (user.getUsername().equals("jon")){
                return new ModelAndView("echo", "user", user);
            }
        }else 
            return new ModelAndView("oops", "user", user);

    }

With a return nested in a double if. it seems java is complaining about this not being a viable return statement ? Why is this an error ?

Aucun commentaire:

Enregistrer un commentaire