In my code, when I try to deserialize the HashSet object it gives me this warnings :
Unchecked assignment:'java.util.HashSet' to'java.util.HashSet<java.lang.Integer>
Inspection info: Signals places where an unchecked warning is issued
by the compiler, for example:
void f(HashMap map) { map.put("key", "value"); }
Hint: Pass -Xlint:unchecked to javac to get more details.
Is this a critical warning ? or should I use @SuppressWarnig ?
How can I eliminate this warning ? please help me guys I'm new in Java
My Code is :
public class Main{
public static void main(String[] args){
HashSet<Integer> number=new HashSet<>();
Scanner input=new Scanner(System.in);
int option;
while(true){
System.out.println("1. add 2. display 3. save 4. load 5. exit");
option=input.nextInt();
if(option==1){
System.out.println("Adding : "+ number.add(1));
System.out.println("Adding : " + number.add(2));
}else if(option==2){
System.out.println("Set is : "+ number);
}else if(option==3){
try{
FileOutputStream fos=new FileOutputStream("data.bin");
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(number);
oos.close();
fos.close();
}catch(IOException e){
e.getMessage();
}
}else if(option==4){
try{
FileInputStream fis=new FileInputStream("data.bin");
ObjectInputStream ois=new ObjectInputStream(fis);
number=(HashSet)ois.readObject(); // this line give me warning
}catch(IOException | ClassNotFoundException e){
e.getMessage();
}
}else if(option==5){
break;
}
}
}
}