test/tools/javac/valhalla/minimalvalues/CheckIdentityHash.java

Print this page


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @summary Value types do not support identityHashCode
   4  * @modules java.base/jvm.internal.value
   5  * @compile/fail/ref=CheckIdentityHash.out -XDrawDiagnostics -Werror -Xlint:values  CheckIdentityHash.java
   6  */
   7 @jvm.internal.value.DeriveValueType
   8 final class CheckIdentityHash {
   9     int identityHashCode(CheckIdentityHash x) {
  10         return 0;
  11     }
  12     void test(CheckIdentityHash v) {
  13         this.identityHashCode(v);      // <- ok
  14         System.identityHashCode(v);    // <- error
  15         System.identityHashCode(this); // <- error
  16         java.lang.System.identityHashCode(v);    // <- error
  17         java.lang.System.identityHashCode(this); // <- error
  18     }
  19 }
   1 /*
   2  * @test /nodynamiccopyright/
   3  * @summary Value types do not support identityHashCode
   4  * @modules java.base/jvm.internal.value
   5  * @compile/fail/ref=CheckIdentityHash.out -XDrawDiagnostics -Werror -Xlint:values  CheckIdentityHash.java
   6  */
   7 @jvm.internal.value.ValueCapableClass
   8 final class CheckIdentityHash {
   9     int identityHashCode(CheckIdentityHash x) {
  10         return 0;
  11     }
  12     void test(CheckIdentityHash v) {
  13         this.identityHashCode(v);      // <- ok
  14         System.identityHashCode(v);    // <- error
  15         System.identityHashCode(this); // <- error
  16         java.lang.System.identityHashCode(v);    // <- error
  17         java.lang.System.identityHashCode(this); // <- error
  18     }
  19 }