Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2006

Tip: Looking for answers? Try searching our database.

Type safety ... References to generic type Enumeration<E> should be parameterized

Thread view: 
Ian Wilson - 30 Aug 2006 10:22 GMT
In Eclipse, this code produces a warning at "foo.nextElement()" saying

"Type safety: The method nextElement() belongs to the raw type
Enumeration. References to generic type Enumeration<E> should be
parameterized"

    void listDefaults() {
        UIDefaults uiDefaults = UIManager.getDefaults();
        Enumeration foo = uiDefaults.keys();
        while (foo.hasMoreElements()) {
            Object key = foo.nextElement();
            Object val = uiDefaults.get(key);
            System.out.println("[" + key.toString() + "]:["
                    + (null != val ? val.toString() : "(null)") + "]");
        }
    }

How should I fix this?
Hendrik Maryns - 30 Aug 2006 11:09 GMT
Ian Wilson schreef:
> In Eclipse, this code produces a warning at "foo.nextElement()" saying
>
[quoted text clipped - 14 lines]
>
> How should I fix this?

By doing as it says:

Enumeration<Object> foo = uiDefaults.keys()

Or have a look at the API of UIDefaults, to see whether it is some more
specific Enumeration (I suppose not).

H.
- --
Hendrik Maryns

==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Dale King - 30 Aug 2006 15:26 GMT
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 25 lines]
> Or have a look at the API of UIDefaults, to see whether it is some more
> specific Enumeration (I suppose not).

It's not. UIDefaults is a subclass of Hashtable<Object,Object> (yet
another example of inappropriate use of inheritance instead of composition).

Signature

 Dale King

Ian Wilson - 30 Aug 2006 15:41 GMT
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
[quoted text clipped - 23 lines]
>
> Enumeration<Object> foo = uiDefaults.keys()

Thanks, I must read more about Generics and reduce my level of bafflement.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.