arcanine08 arcanine08 - 2 months ago 17
Java Question

Unchecked operation warning

What is causing this warning in my program>? I'm giving the inputs by command line. I'm getting this warning for all vector programs.

import java.util.*;
class vect
{
public static void main(String args[])
{
Vector v=new Vector();
int length=args.length;
for(int i=0;i<length;i++)
{
v.addElement(args[i]);
}
System.out.println("Objects in vector are :");
for(int i=0;i<length;i++)
{
System.out.println(v.elementAt(i));
}
}
}`

C:\myJava>javac vect.java
Note: vect.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.`

Answer

You have a Vector without a type. You are then adding to it the arguments which are Strings. This Vector should be type safe.

Vector<String> v = new Vector<String>();
Comments