src/share/classes/java/util/concurrent/ArrayBlockingQueue.java

Print this page

        

@@ -129,12 +129,13 @@
     }
 
     /**
      * Returns item at index i.
      */
+    @SuppressWarnings("unchecked")
     final E itemAt(int i) {
-        return this.<E>cast(items[i]);
+        return (E) items[i];
     }
 
     /**
      * Throws NullPointerException if argument is null.
      *

@@ -160,11 +161,11 @@
      * Extracts element at current take position, advances, and signals.
      * Call only when holding lock.
      */
     private E extract() {
         final Object[] items = this.items;
-        E x = this.<E>cast(items[takeIndex]);
+        @SuppressWarnings("unchecked") E x = (E) items[takeIndex];
         items[takeIndex] = null;
         takeIndex = inc(takeIndex);
         --count;
         notFull.signal();
         return x;

@@ -645,11 +646,12 @@
         try {
             int i = takeIndex;
             int n = 0;
             int max = count;
             while (n < max) {
-                c.add(this.<E>cast(items[i]));
+                @SuppressWarnings("unchecked") E x = (E) items[i];
+                c.add(x);
                 items[i] = null;
                 i = inc(i);
                 ++n;
             }
             if (n > 0) {

@@ -682,11 +684,12 @@
         try {
             int i = takeIndex;
             int n = 0;
             int max = (maxElements < count) ? maxElements : count;
             while (n < max) {
-                c.add(this.<E>cast(items[i]));
+                @SuppressWarnings("unchecked") E x = (E) items[i];
+                c.add(x);
                 items[i] = null;
                 i = inc(i);
                 ++n;
             }
             if (n > 0) {