< prev index next >

src/java.base/share/classes/java/lang/ref/Reference.java

Print this page
@@ -495,10 +495,14 @@
      Reference(T referent) {
          this(referent, null);
      }
  
      Reference(T referent, ReferenceQueue<? super T> queue) {
+         if (referent != null && referent.getClass().isPrimitiveClass()) {
+             throw new IllegalArgumentException("cannot reference a primitive type: " +
+                     referent.getClass().getName());
+         }
          this.referent = referent;
          this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
      }
  
      /**
< prev index next >