< prev index next >

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

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