Skip to main content

Properties Cast to Map? ok in 5.0, compile error in 6.0Beta

2 replies [Last post]
gestaltsolution
Offline
Joined: 2004-11-14
Points: 0

Java 5.0 compiler allowed:
(Map )(System.getProperties());

Java 6 Compiler reports:
found : java.util.Properties
required: java.util.Map
retVal = (Map )(System.getProperties());

While this is probably what "should" be reported, based on the Javadoc showing the superclass, since it is a properties file, why not subclass as

This impacts a Very large codebase.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tackline
Offline
Joined: 2003-06-19
Points: 0

If Properties did extend Hashtable, then old code that extends Properties may not compile. Also client code can legitimately store non-Strings in Properties objects. The real mistake was making Properties extend Hashtable.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4988920

The JDK 1.5 javac has a bug (or two) handling classes that specify specific generic parameters of their superclass. Code that exploits that bug should be fixed (or you could hack it with an intermediate cast to Map).

alexlamsl
Offline
Joined: 2004-09-02
Points: 0

Does the code compile without a single unchecked warning on Tiger? If so that would be a bug in Java SE 5.

IMO, the statement should read:
[code]Map retVal = (Map) System.getProperties();[/code]