By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,798 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,798 IT Pros & Developers. It's quick & easy.

Is this compiler warning impossible to get rid of?

P: n/a
Hi all,

I'm talking about of the following warning:
"myClass.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details."

Usually when this warning occours for a LinkedList or for other linear
structures, is sufficient to declare the type, e.g.:
LinkedList<Integerlist = new LinkedList<Integer>();
and the warning disappears.

but in my case, I have an array of Java's LinkedLists, and I didn't find the
way to get rid of the warning!
Does anyone have an idea?

My declaration (the structure is a separated chaining hash which works
well):

class HashSeparateChaining
{
protected int hashSize;
protected LinkedList[] hash;

public HashSeparateChaining (int size)
{
hashSize = size;
inCount = 0;
outCount = 0;
hash = new LinkedList[hashSize];
for(int i = 0; i < hashSize; i++)
hash[i] = new LinkedList();
}

// rest of the class
// [.......................]
}

Thanks in advance.

--
ciao
Vittorix
Nov 16 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Vittorix <vi******@gmail.comwrote:
>I'm talking about of the following warning:
"myClass.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details."
>Usually when this warning occours for a LinkedList or for other linear
structures, is sufficient to declare the type, e.g.:
LinkedList<Integerlist = new LinkedList<Integer>();
and the warning disappears.
Yes, this is the safe way to do it. You actually fix it rather than just
suppressing the warning.
>but in my case, I have an array of Java's LinkedLists, and I didn't find the
way to get rid of the warning!
Add @SuppressWarnings("unchecked") to the variable, method, or class in
question. This instructs the compiler (and other tools, like Eclipse) that
you've examined this usage and don't want to be warned about it. See
http://java.sun.com/j2se/1.5.0/docs/...sWarnings.html
for (a little bit) more info.

Javac ignored this attribute until a fairly recent patch release (_06 or so,
I'm unsure, I know 1.5.0_08 honors it).
--
Mark Rafn da***@dagon.net <http://www.dagon.net/>
Nov 17 '06 #2

P: n/a
"Mark Rafn"
>>but in my case, I have an array of Java's LinkedLists, and I didn't find
the
way to get rid of the warning!

Add @SuppressWarnings("unchecked") to the variable, method, or class in
question. This instructs the compiler (and other tools, like Eclipse)
that
you've examined this usage and don't want to be warned about it.
thanks a lot Mark!
It is more like a workaround than a solution (there is no solution) but it
works fine.

--
ciao
Vittorix
Nov 17 '06 #3

P: n/a
Lew
Vittorix wrote:
class HashSeparateChaining
{
protected int hashSize;
protected LinkedList[] hash;
Two side points:

Was this class truly not declared "public"? It is rare to need a non-public
class set up to be inherited.

Since you declared "protected" members, is it true that you intend this class
to be inherited? There are dangers to making classes heritable; one has to
build in guards against malicious or careless use on the part of child classes.

Of course, making the class non-public does limit this possibility, but it
might not be sufficient substitute for declaring methods final, etc.

One should usually either declare a class "final" or take steps to make its
inheritance safe.

These considerations might not apply if this is a class meant neither for
distribution nor a long life in production. OTOH, the discipline of making all
one's code "production-ready" is good for one's chops.

"Practice doesn't make perfect; perfect practice makes perfect."

- Lew
Dec 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.