Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vector : References to generic type Vector<E> should be parameterized

I have this problem(yellow line) in my jsp file which often caused my eclipse program keep no responding. Although my program can run, but how can i get a rid of this following line of code.

enter image description here

Vector vFieldName       = (Vector) session.getAttribute("table_vFieldName_"+TABLE_TYPE);
Vector vTable           = session.getAttribute("table_vTable_"+TABLE_TYPE) == null ? new Vector(): (Vector) session.getAttribute("table_vTable_"+TABLE_TYPE);   

for (int k=0;k<vTable.size();k++)
{
   intSeqNo=vTable.size();
   Vector vRow  = (Vector) vTable.elementAt(k);       
}
like image 430
user3835327 Avatar asked Oct 31 '22 01:10

user3835327


1 Answers

I don't think so these warnings would hang your IDE, these are harmless. And also it is always a best practice to specify the type for generics like Vectar<Object> or Vectar<String> or List<String> or ArrayList<String> etc and not use raw types.

Please read from updated sources and books. It is the era of Java-8 and not Java-1!

Anyways if still you want to get rid of these warnings then:

  1. Right click on your project
  2. Go to Properties
  3. Search for "JSP"
  4. Select JSP syntax and scroll down to Java as shown:

    Project properties/Preferences for JSP

  5. Click on Error/Warnings as shown

  6. Scroll down to Generic types and select "Ignore" for Usage of raw types as shown:

    Generic types settings for the project

  7. Apply, rebuild project and you are done.

Also as a side suggestion, it is better to use ArrayList or other Lists instead of Vectar. See this SO answer for why not to use Vectar.

Also avoid using Java code as much as possible in JSPs though sometimes it might be necessary but in most case we can avoid. Use el or jstl instead.

like image 82
Prakash K Avatar answered Dec 07 '22 03:12

Prakash K