Class VarHandleAccessor<T>
java.lang.Object
cloud.opencode.base.reflect.accessor.VarHandleAccessor<T>
- Type Parameters:
T- the target type | 目标类型
- All Implemented Interfaces:
PropertyAccessor<T>
VarHandle-based Property Accessor
基于VarHandle的属性访问器
High-performance property access using VarHandle. Provides atomic operations and memory fence semantics.
使用VarHandle的高性能属性访问。 提供原子操作和内存屏障语义。
Features | 主要功能:
- VarHandle-based high-performance access - 基于VarHandle的高性能访问
- Atomic operations (CAS, getAndSet) - 原子操作(CAS, getAndSet)
- Volatile and acquire/release semantics - Volatile和获取/释放语义
Usage Examples | 使用示例:
VarHandleAccessor<Counter> accessor = VarHandleAccessor.of(Counter.class, "count");
accessor.compareAndSet(counter, 0, 1);
Object value = accessor.getVolatile(counter);
Security | 安全性:
- Thread-safe: Yes (VarHandle operations are atomic) - 线程安全: 是(VarHandle操作是原子的)
- Null-safe: No (caller must ensure non-null target for instance fields) - 空值安全: 否(实例字段须确保非空目标)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncompareAndExchange(T target, Object expectedValue, Object newValue) Atomically compares and exchanges value 原子比较并交换值booleancompareAndSet(T target, Object expectedValue, Object newValue) Atomically compares and sets value 原子比较并设置值booleanstatic <T> VarHandleAccessor<T> Creates a VarHandleAccessor from a field 从字段创建VarHandleAccessorGets the property value 获取属性值getAcquire(T target) Gets value with acquire semantics 以获取语义获取值Atomically adds to value (for numeric types) 原子加法(用于数值类型)Atomically gets and sets value 原子获取并设置值Gets the declaring class 获取声明类Gets the generic property type 获取泛型属性类型getName()Gets the property name 获取属性名Class<?> getType()Gets the property type 获取属性类型Gets the underlying VarHandle 获取底层VarHandlegetVolatile(T target) Gets value with volatile semantics 以volatile语义获取值inthashCode()booleanChecks if property is readable 检查属性是否可读booleanisStatic()Checks if this is a static field 检查是否为静态字段booleanChecks if property is writable 检查属性是否可写static <T> VarHandleAccessor<T> Creates a VarHandleAccessor for a field by name 按名称为字段创建VarHandleAccessorvoidSets the property value 设置属性值voidsetRelease(T target, Object value) Sets value with release semantics 以释放语义设置值voidsetVolatile(T target, Object value) Sets value with volatile semantics 以volatile语义设置值toString()Methods inherited from interface PropertyAccessor
get, getOrDefault, setIfWritable
-
Method Details
-
fromField
Creates a VarHandleAccessor from a field 从字段创建VarHandleAccessor- Type Parameters:
T- the target type | 目标类型- Parameters:
field- the field | 字段- Returns:
- the accessor | 访问器
-
of
Creates a VarHandleAccessor for a field by name 按名称为字段创建VarHandleAccessor- Type Parameters:
T- the target type | 目标类型- Parameters:
clazz- the class | 类fieldName- the field name | 字段名- Returns:
- the accessor | 访问器
-
getVarHandle
Gets the underlying VarHandle 获取底层VarHandle- Returns:
- the VarHandle | VarHandle
-
getName
Description copied from interface:PropertyAccessorGets the property name 获取属性名- Specified by:
getNamein interfacePropertyAccessor<T>- Returns:
- the property name | 属性名
-
getType
Description copied from interface:PropertyAccessorGets the property type 获取属性类型- Specified by:
getTypein interfacePropertyAccessor<T>- Returns:
- the property type | 属性类型
-
getGenericType
Description copied from interface:PropertyAccessorGets the generic property type 获取泛型属性类型- Specified by:
getGenericTypein interfacePropertyAccessor<T>- Returns:
- the generic type | 泛型类型
-
getDeclaringClass
Description copied from interface:PropertyAccessorGets the declaring class 获取声明类- Specified by:
getDeclaringClassin interfacePropertyAccessor<T>- Returns:
- the declaring class | 声明类
-
isReadable
public boolean isReadable()Description copied from interface:PropertyAccessorChecks if property is readable 检查属性是否可读- Specified by:
isReadablein interfacePropertyAccessor<T>- Returns:
- true if readable | 如果可读返回true
-
isWritable
public boolean isWritable()Description copied from interface:PropertyAccessorChecks if property is writable 检查属性是否可写- Specified by:
isWritablein interfacePropertyAccessor<T>- Returns:
- true if writable | 如果可写返回true
-
isStatic
public boolean isStatic()Checks if this is a static field 检查是否为静态字段- Returns:
- true if static | 如果是静态返回true
-
get
Description copied from interface:PropertyAccessorGets the property value 获取属性值- Specified by:
getin interfacePropertyAccessor<T>- Parameters:
target- the target object | 目标对象- Returns:
- the value | 值
-
set
Description copied from interface:PropertyAccessorSets the property value 设置属性值- Specified by:
setin interfacePropertyAccessor<T>- Parameters:
target- the target object | 目标对象value- the value | 值
-
getVolatile
-
setVolatile
-
getAndSet
-
compareAndSet
-
compareAndExchange
-
getAndAdd
-
getAcquire
-
setRelease
-
equals
-
hashCode
-
toString
-