< prev index next >

src/java.base/share/classes/java/lang/invoke/VarHandle.java

Print this page
rev 53074 : 8215648: remove equals and hashCode implementations from j.l.i.VarHandle


1848         }
1849     }
1850 
1851     static final class AccessDescriptor {
1852         final MethodType symbolicMethodTypeErased;
1853         final MethodType symbolicMethodTypeInvoker;
1854         final Class<?> returnType;
1855         final int type;
1856         final int mode;
1857 
1858         public AccessDescriptor(MethodType symbolicMethodType, int type, int mode) {
1859             this.symbolicMethodTypeErased = symbolicMethodType.erase();
1860             this.symbolicMethodTypeInvoker = symbolicMethodType.insertParameterTypes(0, VarHandle.class);
1861             this.returnType = symbolicMethodType.returnType();
1862             this.type = type;
1863             this.mode = mode;
1864         }
1865     }
1866 
1867     /**
1868      * Compare this {@linkplain VarHandle} with another object for equality.
1869      * Two {@linkplain VarHandle}s are considered equal if they both describe the
1870      * same instance field, both describe the same static field, both describe
1871      * array elements for arrays with the same component type, or both describe
1872      * the same component of an off-heap structure.
1873      *
1874      * @param o the other object
1875      * @return Whether this {@linkplain VarHandle} is equal to the other object
1876      */
1877     @Override
1878     public final boolean equals(Object o) {
1879         if (this == o) return true;
1880         if (o == null || getClass() != o.getClass()) return false;
1881 
1882         VarHandle that = (VarHandle) o;
1883         return accessModeType(AccessMode.GET).equals(that.accessModeType(AccessMode.GET)) &&
1884                internalEquals(that);
1885     }
1886 
1887     abstract boolean internalEquals(VarHandle vh);
1888 
1889     @Override
1890     public final int hashCode() {
1891         return 31 * accessModeType(AccessMode.GET).hashCode() + internalHashCode();
1892     }
1893 
1894     abstract int internalHashCode();
1895 
1896     /**
1897      * Returns a compact textual description of this {@linkplain VarHandle},
1898      * including the type of variable described, and a description of its coordinates.
1899      *
1900      * @return A compact textual description of this {@linkplain VarHandle}
1901      */
1902     @Override
1903     public final String toString() {
1904         return String.format("VarHandle[varType=%s, coord=%s]",
1905                              varType().getName(),
1906                              coordinateTypes());
1907     }
1908 
1909     /**
1910      * Returns the variable type of variables referenced by this VarHandle.
1911      *
1912      * @return the variable type of variables referenced by this VarHandle
1913      */
1914     public final Class<?> varType() {
1915         MethodType typeSet = accessModeType(AccessMode.SET);
1916         return typeSet.parameterType(typeSet.parameterCount() - 1);




1848         }
1849     }
1850 
1851     static final class AccessDescriptor {
1852         final MethodType symbolicMethodTypeErased;
1853         final MethodType symbolicMethodTypeInvoker;
1854         final Class<?> returnType;
1855         final int type;
1856         final int mode;
1857 
1858         public AccessDescriptor(MethodType symbolicMethodType, int type, int mode) {
1859             this.symbolicMethodTypeErased = symbolicMethodType.erase();
1860             this.symbolicMethodTypeInvoker = symbolicMethodType.insertParameterTypes(0, VarHandle.class);
1861             this.returnType = symbolicMethodType.returnType();
1862             this.type = type;
1863             this.mode = mode;
1864         }
1865     }
1866 
1867     /**





























1868      * Returns a compact textual description of this {@linkplain VarHandle},
1869      * including the type of variable described, and a description of its coordinates.
1870      *
1871      * @return A compact textual description of this {@linkplain VarHandle}
1872      */
1873     @Override
1874     public final String toString() {
1875         return String.format("VarHandle[varType=%s, coord=%s]",
1876                              varType().getName(),
1877                              coordinateTypes());
1878     }
1879 
1880     /**
1881      * Returns the variable type of variables referenced by this VarHandle.
1882      *
1883      * @return the variable type of variables referenced by this VarHandle
1884      */
1885     public final Class<?> varType() {
1886         MethodType typeSet = accessModeType(AccessMode.SET);
1887         return typeSet.parameterType(typeSet.parameterCount() - 1);


< prev index next >