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

ReentrantReadWriteLock documentation example has compile time error

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      'RWDictionary' example contains compile time error. The next piece of code cannot be compiled:

      public String[] allKeys() {
              r.lock();
              try { return m.keySet().toArray(); }
              finally { r.unlock(); }
          }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      it should be:
      return m.keySet().toArray(new String[0]);
      ACTUAL -
      error: incompatible types
              try { return m.keySet().toArray(); }
                                             ^
        required: String[]
        found: Object[]

      URL OF FAULTY DOCUMENTATION :
      http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/ReentrantReadWriteLock.html

            martin Martin Buchholz
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: