Re: Beginner's Question: "*.java uses unchecked or unsafe operations"




"sunbin" <noSpam@xxxxxxxxxx> wrote in message
news:eftt69$ivu$1@xxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all

I have read the net and notice this problem is caused by the version of
compiler between 1.5 and 1.4.

I tried to use the follow codes to overcome the warning msg. "uses
unchecked or unsafe operations" but not able to. Please advice. Thanks.

[code]

public class XXX
{
private ArrayList <Customer> CustDB;
.....
.....
public static void main(String[] args)
{
......
......
......
FileInputStream readFile = new FileInputStream("cust.dat");
ObjectInputStream read = new ObjectInputStream(readFile);

CustDB = (ArrayList<Customer>)read.readObject();
}
}

[/code]

I tried to typecast the read object, but yet the warning still exists.
May I know where have I did wrong?

Specifically, change the cast to:

CustDB = (ArrayList<?>)read.readObject();

you'll probably have to add some more casts later on in your code in
addition to making this change.

In general, don't supply generic type arguments in cast expressions.

- Oliver


.



Relevant Pages

  • Beginners Question: "*.java uses unchecked or unsafe operations"
    ... I tried to use the follow codes to overcome the warning msg. ... public static void main ... ObjectInputStream read = new ObjectInputStream; ...
    (comp.lang.java.help)
  • Re: Generics warning message.
    ... runExample (ois); ... It returns an appropriate ObjectInputStream ... How to cast it out without throwing warnings? ...
    (comp.lang.java.programmer)
  • Re: unchecked cast
    ... senderj wrote: ... My coding is like this: ... ObjectInputStream si = new ObjectInputStream; ... on that cast. ...
    (comp.lang.java.programmer)