A DESCRIPTION OF THE REQUEST :
java.util.Properties should offer an Iterator for the keys. So far, only the keySet() from the superclass Hashtable can be used for this. But Hashtable has the generic type specification <Object, Object>. So you can't use the for-each loop
for (String key : p.keySet()) {
...
}
but only
for (Object key : p.keySet()) {
String skey = (String) key;
...
}
JUSTIFICATION :
A proper Iterator would made it unnecessary to cast each key Object to String.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Calling keySet() on a Properties object should return Set<String> instead of the Properties superclass Set<Object>.
---------- BEGIN SOURCE ----------
import java.util.Properties;
public class Test {
public static void main(String[] args) {
//iterate through Properties:
Properties p = System.getProperties();
for (String key : p.keySet()) { //doesn't work
System.out.println(key+": "+p.getProperty(key));
}
}
}
---------- END SOURCE ----------
###@###.### 2005-04-11 17:56:57 GMT
java.util.Properties should offer an Iterator for the keys. So far, only the keySet() from the superclass Hashtable can be used for this. But Hashtable has the generic type specification <Object, Object>. So you can't use the for-each loop
for (String key : p.keySet()) {
...
}
but only
for (Object key : p.keySet()) {
String skey = (String) key;
...
}
JUSTIFICATION :
A proper Iterator would made it unnecessary to cast each key Object to String.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Calling keySet() on a Properties object should return Set<String> instead of the Properties superclass Set<Object>.
---------- BEGIN SOURCE ----------
import java.util.Properties;
public class Test {
public static void main(String[] args) {
//iterate through Properties:
Properties p = System.getProperties();
for (String key : p.keySet()) { //doesn't work
System.out.println(key+": "+p.getProperty(key));
}
}
}
---------- END SOURCE ----------
###@###.### 2005-04-11 17:56:57 GMT
- relates to
-
JDK-8059361 (spec) Properties.stringPropertyNames() returns a set inconsistent with the assertions from the spec
-
- Closed
-
-
JDK-6260131 sun.management.RuntimeImpl's SystemProperties attribute gives partial results
-
- Resolved
-