Xlint " warning: [unchecked] unchecked conversion"

R

RVic

How can I eliminate " warning: [unchecked] unchecked conversion" in
the following line ???

Vector <String> v = (Vector)this.hashtable.get(key);
 
D

Donkey Hottie

RVic said:
How can I eliminate " warning: [unchecked] unchecked
conversion" in the following line ???

Vector <String> v = (Vector)this.hashtable.get(key);

You define the hashtable as

HashTable<String, Vector<String>> hashtable = new HashTable<String,
Vector<String>>() ;
 
D

Donkey Hottie

RVic said:
How can I eliminate " warning: [unchecked] unchecked
conversion" in the following line ???

Vector <String> v = (Vector)this.hashtable.get(key);

... and remove the reduntand cast to Vector, of course.
 
D

Donkey Hottie

RVic said:
How can I eliminate " warning: [unchecked] unchecked
conversion" in the following line ???

Vector <String> v = (Vector)this.hashtable.get(key);

Note that both Vector and HashTable are kind of deprecated features. If you
do not need syncronization, your should upgrade

Vector -> ArrayList using interface List
HashTable -> HashMap using interface Map
 
R

RVic

Yes, that works, but what then about:

Hashtable getHashtable() {
return this.hashtable;
}
.
.
.
public static void main(String[] args) throws Exception {
Hashtable <String, Vector<String>> ht = MyClass.getHashtable();
.
.
}

How do I eliminate the "warning: [unchecked] unchecked conversion"
warning for that line in main()? i.e. how do I put the notation
<String, Vector<String>> to the rigth of the equals sign?
 
D

Donkey Hottie

RVic said:
Yes, that works, but what then about:

Hashtable getHashtable() {
return this.hashtable;
}
.
.
.
public static void main(String[] args) throws Exception {
Hashtable <String, Vector<String>> ht =
MyClass.getHashtable(); .
.
}

How do I eliminate the "warning: [unchecked] unchecked
conversion" warning for that line in main()? i.e. how do
I put the notation <String, Vector<String>> to the rigth
of the equals sign?

You re-decrade all definitions again.

Hashtable<String, Vector<String, Vector<String>> getHashtable() {
return this.hashtable;
}
 
M

Mayeul

RVic said:
Yes, that works, but what then about:

Hashtable getHashtable() {
return this.hashtable;
}
.
.
.
public static void main(String[] args) throws Exception {
Hashtable <String, Vector<String>> ht = MyClass.getHashtable();
.
.
}

How do I eliminate the "warning: [unchecked] unchecked conversion"
warning for that line in main()? i.e. how do I put the notation
<String, Vector<String>> to the rigth of the equals sign?

You don't.

You just modify getHashtable() declaration as

Hashtable<String, Vector<String>> getHashtable() {
return this.hashtable;
}

and probably modify that "this.hashtable" so that it is declared as a
Hashtable<String, Vector<String>>.

I suppose this will be along the lines of:

private Hashtable<String, Vector<String>> hashtable = new
Hashtable<String, Vector<String>>();

This is basic generics usage, really.
 
L

Lew

How can I eliminate " warning: [unchecked] unchecked
conversion" in the following line ???
Vector <String> v = (Vector)this.hashtable.get(key);

You define the hashtable as

    HashTable<String, Vector<String>> hashtable = new HashTable<String,
Vector<String>>() ;

HashTable is not a standard API class.
 
L

Lew

How can I eliminate " warning: [unchecked] unchecked
conversion" in the following line ???
Vector <String> v = (Vector)this.hashtable.get(key);

Note that both Vector and HashTable [sic] are kind of deprecated features.. If you
do not need syncronization, your should upgrade

Vector -> ArrayList using interface List
HashTable [sic] -> HashMap using interface Map

And if you do need synchronization, you should upgrade also.
 
L

Lew

Yes, that works, but what then about:

 Hashtable getHashtable() {
    return this.hashtable;
  }
  .
  .
  .
public static void main(String[] args) throws Exception {
    Hashtable <String, Vector<String>> ht =  MyClass.getHashtable();
    .
    .
    }

How do I eliminate the  "warning: [unchecked] unchecked conversion"
warning for that line in main()? i.e. how do I put the notation
<String, Vector<String>> to the rigth of the equals sign?

Don't use raw types ever.

Define 'getHashtable()' (terrible practice to return a specific
concrete type) in terms of generics. You have it returning a raw
type. Bad practice.
 
L

Lew

Yes, that works, but what then about:
Hashtable getHashtable() {
   return this.hashtable;
 }
 .
 .
 .
public static void main(String[] args) throws Exception {
   Hashtable <String, Vector<String>> ht =
   MyClass.getHashtable(); .
   .
   }
How do I eliminate the  "warning: [unchecked] unchecked
conversion" warning for that line in main()? i.e. how do
I put the notation <String, Vector<String>> to the rigth
of the equals sign?

You re-decrade all definitions again.

Hashtable<String, Vector<String, Vector<String>> getHashtable() {
   return this.hashtable;

}

Even better, rename 'this.hashtable' and define as the interface
types:

public class Foo
{
private final Map <String, List <String>> table =
new HashMap <String, List <String>> ();
// or Hashtable, ConcurrentHashMap, ...

public final Map <String, List <String>> getTable()
{
return this.table;
}
}

You can even make the class generic:

public class Foo <K, T>
{
private final Map <K, List <T>> table =
new HashMap <K, List <T>> ();
// or Hashtable, ConcurrentHashMap, TreeMap, ...
// but not Hashtable

public final Map <K, List <T>> getTable()
{
return this.table;
}
}
 
R

Roedy Green

How can I eliminate " warning: [unchecked] unchecked conversion" in
the following line ???

Vector <String> v = (Vector)this.hashtable.get(key);

Buy yourself a very tall drink of your favourite hot beverage.
Then start reading at

http://mindprod.com/jgloss/generics.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

"The industrial civilisation is based on the consumption of energy resources that are inherently limited in quantity, and that are about to become scarce. When they do, competition for what remains will trigger dramatic economic and geopolitical events; in the end, it may be impossible for even a single nation to sustain industrialism as we have know it in the twentieth century."
~ Richard Heinberg, The Party’s Over: Oil, War, and the Fate of Industrial Societies
 
L

Lew

RVic wrote, quoted or indirectly quoted someone who said :
How can I eliminate " warning: [unchecked] unchecked conversion" in
the following line ???
Vector <String> v = (Vector)this.hashtable.get(key);

Roedy said:
Buy yourself a very tall drink of your favourite hot beverage.

I prefer a cold one this time of year.

Read and study
<http://java.sun.com/docs/books/effective/generics.pdf>
 
R

Roedy Green

How can I eliminate " warning: [unchecked] unchecked conversion" in

see http://mindprod.com/jgloss/compileerrormessages.html#UNCHECKED
--
Roedy Green Canadian Mind Products
http://mindprod.com

"The industrial civilisation is based on the consumption of energy resources that are inherently limited in quantity, and that are about to become scarce. When they do, competition for what remains will trigger dramatic economic and geopolitical events; in the end, it may be impossible for even a single nation to sustain industrialism as we have know it in the twentieth century."
~ Richard Heinberg, The Party’s Over: Oil, War, and the Fate of Industrial Societies
 
A

Arne Vajhøj

Lew said:
RVic said:
How can I eliminate " warning: [unchecked] unchecked
conversion" in the following line ???
Vector <String> v = (Vector)this.hashtable.get(key);
You define the hashtable as

HashTable<String, Vector<String>> hashtable = new HashTable<String,
Vector<String>>() ;

HashTable is not a standard API class.

No, but Hashtable is.

And given the context then ...

Arne
 
D

Donkey Hottie

Lew said:
You shouldn't misspell class names is my point. In case
it wasn't obvious.

I ALWAYS misspell Hashtable. It does not follow Sun's current convention for
class names.
 
R

Roedy Green

HashTable is not a standard API class.

java.util.Hashtable (not lower case t) or preferably now,
java.util.HashMap
--
Roedy Green Canadian Mind Products
http://mindprod.com

"The industrial civilisation is based on the consumption of energy resources that are inherently limited in quantity, and that are about to become scarce. When they do, competition for what remains will trigger dramatic economic and geopolitical events; in the end, it may be impossible for even a single nation to sustain industrialism as we have know it in the twentieth century."
~ Richard Heinberg, The Party’s Over: Oil, War, and the Fate of Industrial Societies
 

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

No members online now.

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top