473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Is this compiler warning impossible to get rid of?

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
3 4369
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hafeez | last post by:
I am having real trouble compiling this code http://www.cs.wisc.edu/~vganti/birchcode/codeHier/AttrProj.tgz The attachment shows errors when compiled using the current version of g++ in a...
8
by: Charlie Zender | last post by:
Hi, First, this may be a GCC or Linux-specific problem, I'm not sure. I am unable to compile a large body of code with extremely pedantic compile time checks activate, so that warnings cause...
29
by: junky_fellow | last post by:
Consider the following piece of code: struct junk { int i_val; int i_val1; char c_val; }; int main(void) {
10
by: rahul8143 | last post by:
Hello sir, First sorry if seen this as again posted due to network problem. Thanks for pointing me that void main() is wrong to use...
1
by: rahul8143 | last post by:
Hello sir, Thanks for pointing me that void main() is wrong to use ***************************************************************************** > void main() ^^^^ Why do so many people post...
34
by: Bob | last post by:
Hi, The compiler gives Warning 96 Variable 'cmdSource' is used before it has been assigned a value. A null reference exception could result at runtime. Dim cmdSource as SQlClient.SQLDataReader...
11
by: zeppe | last post by:
Hi all, I've a problem. The code that follows creates a warning in both gcc and visual c++. However, I think it's correct: basically, there is a function that return an object of a derived...
31
by: Mark Dufour | last post by:
Hi all, I have recently released version 0.0.20 and 0.0.21 of Shed Skin, an optimizing Python-to-C++ compiler. Shed Skin allows for translation of pure (unmodified), implicitly statically typed...
3
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.