-1

Should I add @Override annotation when overriding doGet() and doPost() methods from javax.servlet.http.HttpServlet?

For example:

@WebServlet("/")
public class MyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        /* my code */
    }
}

I've never seen code that adds @Override annotation to servlet code.

Tripp Kinetics
  • 4,960
  • 2
  • 21
  • 34
  • 1
    Yes, you should always use `@Override` when you can, to document that you are overriding a method, and to guard against not overriding because you got the argument types wrong. – Andreas Apr 03 '18 at 20:18

1 Answers1

0

Always use @Override. It helps catch errors where something has caused the class being extended to change.

Tripp Kinetics
  • 4,960
  • 2
  • 21
  • 34