< prev index next >

test/jdk/valhalla/valuetypes/ValueBootstrapMethods.java

Print this page
rev 55117 : 8223350: [lworld] Use inline classes instead of value classes


  59     public static void main(String... args) throws Throwable {
  60         Class<?> test = valueTestClass();
  61         Value value = Value.make(10, 5.03, "foo", "bar", "goo");
  62 
  63         Class<?> valueClass = Value.class.asValueType();
  64         Method hashCode = test.getMethod("hashCode", valueClass);
  65         int hash = (int)hashCode.invoke(null, value);
  66         assertEquals(hash, value.hashCode());
  67 
  68         Method toString = test.getMethod("toString", valueClass);
  69         String s = (String)toString.invoke(null, value);
  70         assertEquals(s, value.toString());
  71 
  72         Method equals = test.getMethod("equals", valueClass, Object.class);
  73         boolean rc = (boolean)equals.invoke(null, value, value);
  74         if (!rc) {
  75             throw new RuntimeException("expected equals");
  76         }
  77     }
  78 
  79     public static final value class Value {
  80         private final int i;
  81         private final double d;
  82         private final String s;
  83         private final List<String> l;
  84         Value() {
  85             this.i = 0;
  86             this.d = 0;
  87             this.s = "default";
  88             this.l = List.of();
  89         }
  90         public static Value make(int i, double d, String s, String... items) {
  91             Value v = Value.default;
  92             v = __WithField(v.i, i);
  93             v = __WithField(v.d, d);
  94             v = __WithField(v.s, s);
  95             v = __WithField(v.l, List.of(items));
  96             return v;
  97         }
  98 
  99         List<Object> values() {




  59     public static void main(String... args) throws Throwable {
  60         Class<?> test = valueTestClass();
  61         Value value = Value.make(10, 5.03, "foo", "bar", "goo");
  62 
  63         Class<?> valueClass = Value.class.asValueType();
  64         Method hashCode = test.getMethod("hashCode", valueClass);
  65         int hash = (int)hashCode.invoke(null, value);
  66         assertEquals(hash, value.hashCode());
  67 
  68         Method toString = test.getMethod("toString", valueClass);
  69         String s = (String)toString.invoke(null, value);
  70         assertEquals(s, value.toString());
  71 
  72         Method equals = test.getMethod("equals", valueClass, Object.class);
  73         boolean rc = (boolean)equals.invoke(null, value, value);
  74         if (!rc) {
  75             throw new RuntimeException("expected equals");
  76         }
  77     }
  78 
  79     public static final inline class Value {
  80         private final int i;
  81         private final double d;
  82         private final String s;
  83         private final List<String> l;
  84         Value() {
  85             this.i = 0;
  86             this.d = 0;
  87             this.s = "default";
  88             this.l = List.of();
  89         }
  90         public static Value make(int i, double d, String s, String... items) {
  91             Value v = Value.default;
  92             v = __WithField(v.i, i);
  93             v = __WithField(v.d, d);
  94             v = __WithField(v.s, s);
  95             v = __WithField(v.l, List.of(items));
  96             return v;
  97         }
  98 
  99         List<Object> values() {


< prev index next >