Re: Beginner's Question: "*.java uses unchecked or unsafe operations"
"sunbin" <noSpam@noSpam.com> wrote in message
news:eg0nsj$lgt$1@reader01.singnet.com.sg...
"Oliver Wong" <owong@castortech.com> wrote in message
news:l4PUg.12092$N4.4987@clgrps12...
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.
Thanks for the reply.
I dont quite get what you mean. I am precisely doing what your post listed
CustDB = (ArrayList<?>)read.readObject();
but the warning msg just won't get away.
Are you sure? In your original post, you said you wrote:
CustDB = (ArrayList<Customer>)read.readObject();
But I'm telling you to write:
CustDB = (ArrayList<?>)read.readObject();
Notice that I don't pass "Customer" as a generic type argument.
In general, don't supply generic type arguments in cast expressions.
Sorry I do not know what's generic, mind to explain?
To put it informally, generic type arguments are the stuff that appear
between the angle brackets in your code. If you don't understand how they
work, it's probably best not to use them at all (remove everything between
the angle brackets, and the angle brackets themselves), so the code would
look like:
CustDB = (ArrayList)read.readObject();
instead of
CustDB = (ArrayList<Customer>)read.readObject();
You'll get warnings about not using generics, but you should just ignore
them, since you don't know how to use generics yet.
- Oliver