Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I parameterize getParameterNames to avoid the warning

Tags:

java

servlets

    HttpServletRequest request;
    Enumeration params = request.getParameterNames();

How should I declare the return type for the above method?

like image 597
Jason Avatar asked Jun 11 '11 05:06

Jason


1 Answers

This method was parameterized since Servlet API 3.0 (Java EE 6). In older versions like Servlet API 2.5 (Java EE 5) and before this method (and many others) is not parameterized. You're apparently running a Servlet 2.5 container or older. You have basically 2 options:

  1. Upgrade to a Servlet 3.0 container (Tomcat 7, Glassfish 3, JBoss AS 6, etc) so that you can do

    Enumeration<String> params = request.getParameterNames();
    
  2. Make an unchecked cast.

    @SuppressWarnings("unchecked")
    Enumeration<String> params = (Enumeration<String>) request.getParameterNames();
    
like image 108
BalusC Avatar answered Oct 03 '22 15:10

BalusC