Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Xlint " warning: [unchecked] unchecked conversion"

Reply
Thread Tools

Xlint " warning: [unchecked] unchecked conversion"

 
 
Lew
Guest
Posts: n/a
 
      07-24-2009
On Jul 24, 11:59*am, RVic <(E-Mail Removed)> wrote:
> 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.

--
Lew
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      07-24-2009
On Jul 24, 12:05*pm, "Donkey Hottie" <(E-Mail Removed)> wrote:
> "RVic" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)
>
>
>
> > 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;
}
}

--
Lew
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      07-24-2009
On Fri, 24 Jul 2009 08:32:02 -0700 (PDT), RVic <(E-Mail Removed)>
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);


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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      07-24-2009
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 Green wrote:
> Buy yourself a very tall drink of your favourite hot beverage.
>


I prefer a cold one this time of year.

> Then start reading at
>
> http://mindprod.com/jgloss/generics.html
>


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

--
Lew
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-24-2009
On Fri, 24 Jul 2009 08:32:02 -0700 (PDT), RVic <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

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


see http://mindprod.com/jgloss/compileer...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
 
Reply With Quote
 
Arne Vajhřj
Guest
Posts: n/a
 
      07-25-2009
Lew wrote:
> On Jul 24, 11:40 am, "Donkey Hottie" <(E-Mail Removed)> wrote:
>> "RVic" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)
>>> 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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      07-25-2009
Lew wrote:
>> HashTable is not a standard API class.


Arne Vajhøj wrote:
> No, but Hashtable is.
>
> And given the context then ...


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

--
Lew
 
Reply With Quote
 
Donkey Hottie
Guest
Posts: n/a
 
      07-25-2009
"Lew" <(E-Mail Removed)> wrote in message
news:h4dlkk$5di$(E-Mail Removed)
> Lew wrote:
>>> HashTable is not a standard API class.

>
> Arne Vajhøj wrote:
>> No, but Hashtable is.
>>
>> And given the context then ...

>
> 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.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      07-25-2009
On Fri, 24 Jul 2009 09:22:39 -0700 (PDT), Lew <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      07-25-2009
Lew wrote, quoted or indirectly quoted someone who said :
>> HashTable is not a standard API class.


Roedy Green wrote:
> java.util.Hashtable (note lower case t) or preferably now,
> java.util.HashMap


<http://java.sun.com/javase/6/docs/api/java/util/Map.html>
> All Known Subinterfaces:
> Bindings, ConcurrentMap<K,V>, ConcurrentNavigableMap<K,V>,
> LogicalMessageContext, MessageContext, NavigableMap<K,V>,
> SOAPMessageContext, SortedMap<K,V>
>
> All Known Implementing Classes:
> AbstractMap, Attributes, AuthProvider, ConcurrentHashMap,
> ConcurrentSkipListMap, EnumMap, HashMap, Hashtable,
> IdentityHashMap, LinkedHashMap, PrinterStateReasons,
> Properties, Provider, RenderingHints, SimpleBindings,
> TabularDataSupport, TreeMap, UIDefaults, WeakHashMap


--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XLint Francois Lionet Java 2 04-25-2007 11:57 AM
How to add -Xlint in Ant's build.xml file? RC Java 2 03-21-2007 05:57 PM
How to add -Xlint in Ant's build.xml file? RC XML 2 03-21-2007 05:57 PM
errore con l'opzione -Xlint Flex Java 0 01-25-2005 11:57 PM
What is the -Xlint Steve R. Burrus Java 1 03-07-2004 10:02 PM



Advertisments