Java Enumeration is a raw type. References to generic type Enumeration<E> should be parameterized

Enumeration is a raw type. References to generic type Enumeration<E> should be   parameterized

forum.sun.com

--------------------------------------------------------------------------------------------

Hi,

I am getting a compilation warning at the statement
Enumeration<String> params = (Enumeration<String>)request.getParameterNames();

I am facing problem in removing this warning.

I don't want to use @SuppressWarnings("unchecked")

Can anyone please help in removing this warning?

---------------------------------------------------------------------------------------------
I see two options. The first is to change request.getParameterNames() to return Enumeration<String> instead of Enumberation assuming that getParameterNames always returns Strings.
The other is to use a wild card enumeration instead of a Enumeration<String>. Since all objects can be converted to Strings it will allow you to use the Enumeration without getting any class cast exceptions

Enumeration<?> params = request.getParameterNames();
while (params.hasMoreElements())
{
    String value = params.nextElement().toString();
}
 

댓글

이 블로그의 인기 게시물

jquery css

Struts2의 작동 원리

JSP/Servlet 한글 깨짐 처리 ?