Xlint " warning: [unchecked] unchecked conversion"

Discussion in 'Java' started by RVic, Jul 24, 2009.

  1. RVic

    RVic Guest

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

    Vector <String> v = (Vector)this.hashtable.get(key);
    RVic, Jul 24, 2009
    #1
    1. Advertising

  2. "RVic" <> wrote in message
    news:
    > 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>>() ;
    Donkey Hottie, Jul 24, 2009
    #2
    1. Advertising

  3. "RVic" <> wrote in message
    news:
    > 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.
    Donkey Hottie, Jul 24, 2009
    #3
  4. "RVic" <> wrote in message
    news:
    > 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
    Donkey Hottie, Jul 24, 2009
    #4
  5. RVic

    RVic Guest

    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?
    RVic, Jul 24, 2009
    #5
  6. "RVic" <> wrote in message
    news:
    > 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;
    }
    Donkey Hottie, Jul 24, 2009
    #6
  7. RVic

    Mayeul Guest

    RVic 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?


    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.

    --
    Mayeul
    Mayeul, Jul 24, 2009
    #7
  8. RVic

    Lew Guest

    On Jul 24, 11:40 am, "Donkey Hottie" <> wrote:
    > "RVic" <> wrote in message
    >
    > news:
    >
    > > 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.

    --
    Lew
    Lew, Jul 24, 2009
    #8
  9. RVic

    Lew Guest

    On Jul 24, 11:47 am, "Donkey Hottie" <> wrote:
    > "RVic" <> wrote in message
    >
    > news:
    >
    > > 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.

    --
    Lew
    Lew, Jul 24, 2009
    #9
  10. "Lew" <> wrote in message
    news:
    > On Jul 24, 11:40 am, "Donkey Hottie" <>
    > wrote:
    >> "RVic" <> wrote in message
    >>
    >> news:
    >>
    >>> 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.


    Cool :p
    Donkey Hottie, Jul 24, 2009
    #10
  11. RVic

    Lew Guest

    On Jul 24, 11:59 am, RVic <> 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
    Lew, Jul 24, 2009
    #11
  12. RVic

    Lew Guest

    On Jul 24, 12:05 pm, "Donkey Hottie" <> wrote:
    > "RVic" <> wrote in message
    >
    > news:
    >
    >
    >
    > > 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
    Lew, Jul 24, 2009
    #12
  13. RVic

    Roedy Green Guest

    On Fri, 24 Jul 2009 08:32:02 -0700 (PDT), 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);


    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
    Roedy Green, Jul 24, 2009
    #13
  14. RVic

    Lew Guest

    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
    Lew, Jul 24, 2009
    #14
  15. RVic

    Roedy Green Guest

    On Fri, 24 Jul 2009 08:32:02 -0700 (PDT), RVic <>
    wrote, quoted or indirectly quoted someone who said :

    >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
    Roedy Green, Jul 24, 2009
    #15
  16. RVic

    Arne Vajhøj Guest

    Lew wrote:
    > On Jul 24, 11:40 am, "Donkey Hottie" <> wrote:
    >> "RVic" <> wrote in message
    >> news:
    >>> 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
    Arne Vajhøj, Jul 25, 2009
    #16
  17. RVic

    Lew Guest

    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
    Lew, Jul 25, 2009
    #17
  18. "Lew" <> wrote in message
    news:h4dlkk$5di$
    > 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.
    Donkey Hottie, Jul 25, 2009
    #18
  19. RVic

    Roedy Green Guest

    On Fri, 24 Jul 2009 09:22:39 -0700 (PDT), Lew <>
    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
    Roedy Green, Jul 25, 2009
    #19
  20. RVic

    Lew Guest

    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
    Lew, Jul 25, 2009
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve R. Burrus

    What is the -Xlint

    Steve R. Burrus, Mar 7, 2004, in forum: Java
    Replies:
    1
    Views:
    17,152
  2. Flex
    Replies:
    0
    Views:
    483
  3. RC
    Replies:
    2
    Views:
    746
    Greg R. Broderick
    Mar 21, 2007
  4. RC
    Replies:
    2
    Views:
    986
    Greg R. Broderick
    Mar 21, 2007
  5. Francois Lionet

    XLint

    Francois Lionet, Apr 24, 2007, in forum: Java
    Replies:
    2
    Views:
    818
Loading...

Share This Page