Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6253413

java.util.Properties should offer an Iterator<String> for keys

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 5.0
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b53
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mchung Mandy Chung
              Reporter:
              jleesunw Jon Lee (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: