View Full Version : unchecked or Unsafe operations

03-24-2012, 02:06 PM
Hey, This is a small java program for sorting user input into a vector it, sorts and outputs. Im a newbie but it works although it flash a warning
program.java uses unsafe or unchecked operations.
recompile with -XLint: unchecked for details.

Its not the end of the world but this is homework so i can see me getting slated for it.

import java.util.Vector;
import java.util.Collections;
import javax.swing.JOptionPane;
public class VectorSort {

public static void main(String[] args) {

Vector v = new Vector();
String userInput;
for (int i= 0; i<= 5; i++)
userInput = JOptionPane.showInputDialog(null, "Enter words to be sorted now:");


JOptionPane.showMessageDialog(null, "Vector elements after sorting : ");
for(int j=0; j<v.size(); j++)
JOptionPane.showMessageDialog(null, v.get(j));


03-24-2012, 05:50 PM
If you have not yet been taught generics, then you can safely ignore the errors.
The problem is that Vector/Collections are generic types, so you should specify what type of object is allowed within them: Vector<String> v = new Vector<String>();.
If generics have not been covered, I believe the supressWarnings options work at a compiler level. Add this immediately above the method signature:

@SuppressWarnings({ "rawtypes", "unchecked" })