Is this compiler warning impossible to get rid of?

V

Vittorix

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<Integer> list = 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 = new LinkedList();
}

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

Thanks in advance.
 
D

Daniel Pitts

Vittorix said:
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<Integer> list = 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 = new LinkedList();
}

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

Thanks in advance.


What about having an "ArrayList<LinkedList<Type>> hash = new
ArrayList<LinkedList<Type>>()" instead of managing an array yourself?

There is generally no way to handle generics and arrays together the
way you're trying to.
 
V

Vittorix

"Daniel Pitts"
What about having an "ArrayList<LinkedList<Type>> hash = new
ArrayList<LinkedList<Type>>()" instead of managing an array yourself?

yeah, but I wanted to handle things by myself, more efficently
There is generally no way to handle generics and arrays together the
way you're trying to.

thanks, so this is the conclusion.
 
D

Daniel Pitts

Vittorix said:
"Daniel Pitts"


yeah, but I wanted to handle things by myself, more efficently


thanks, so this is the conclusion.

A little advice, Don't handling things yourself "more efficently"
unless you find out (as in, use a profiler) that you need it. Its a
bigger headache than you need.

You're little class might be better replaced by HashMap or HashSet,
depending on what its doing. I would only try to find/create a
different collection type of class if there aren't any standard ones
that work "well enough".
 
V

Vittorix

"Daniel Pitts"
A little advice, Don't handling things yourself "more efficently"
unless you find out (as in, use a profiler) that you need it. Its a
bigger headache than you need.

ok :)
You're little class might be better replaced by HashMap or HashSet,
depending on what its doing. I would only try to find/create a
different collection type of class if there aren't any standard ones
that work "well enough".

you are right, thanks
 
V

Vittorix

"Vittorix"
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<Integer> list = 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!

I found this way to suppress the warning. it is not like fixing it, but it
works:
@SuppressWarnings("unchecked")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top