类 KeyFactory
- java.lang.Object
- org.springframework.cglib.core.KeyFactory
public abstract class KeyFactory extends Object
Generates classes to handle multi-valued keys, for use in things such as Maps and Sets. Code forequals
andhashCode
methods follow the the rules laid out in Effective Java by Joshua Bloch.To generate a
KeyFactory
, you need to supply an interface which describes the structure of the key. The interface should have a single method namednewInstance
, which returns anObject
. The arguments array can be anything--Objects, primitive values, or single or multi-dimension arrays of either. For example:private interface IntStringKey { public Object newInstance(int i, String s); }
Once you have made a
KeyFactory
, you generate a new key by calling thenewInstance
method defined by your interface.IntStringKey factory = (IntStringKey)KeyFactory.create(IntStringKey.class); Object key1 = factory.newInstance(4, "Hello"); Object key2 = factory.newInstance(4, "World");
Note:
hashCode
equality between two keyskey1
andkey2
is only guaranteed ifkey1.equals(key2)
and the keys were produced by the same factory.
嵌套类概要
嵌套类 修饰符和类型 类 说明 static class
KeyFactory.Generator
字段概要
字段 修饰符和类型 字段 说明 static org.springframework.cglib.core.Customizer
CLASS_BY_NAME
static org.springframework.cglib.core.HashCodeCustomizer
HASH_ASM_TYPE
Type.hashCode()
is very expensive as it traverses full descriptor to calculate hash code.static org.springframework.cglib.core.Customizer
OBJECT_BY_CLASS
已过时。this customizer might result in unexpected class leak since key object still holds a strong reference to the Object and class.static org.springframework.cglib.core.FieldTypeCustomizer
STORE_CLASS_AS_STRING
构造器概要
构造器 限定符 构造器 说明 protected
KeyFactory()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static KeyFactory
create(Class keyInterface)
static KeyFactory
create(ClassLoader loader, Class keyInterface, org.springframework.cglib.core.Customizer customizer)
static KeyFactory
create(ClassLoader loader, Class keyInterface, org.springframework.cglib.core.KeyFactoryCustomizer customizer, List<org.springframework.cglib.core.KeyFactoryCustomizer> next)
static KeyFactory
create(Class keyInterface, org.springframework.cglib.core.Customizer customizer)
static KeyFactory
create(Class keyInterface, org.springframework.cglib.core.KeyFactoryCustomizer first, List<org.springframework.cglib.core.KeyFactoryCustomizer> next)
字段详细资料
CLASS_BY_NAME
public static final org.springframework.cglib.core.Customizer CLASS_BY_NAME
STORE_CLASS_AS_STRING
public static final org.springframework.cglib.core.FieldTypeCustomizer STORE_CLASS_AS_STRING
HASH_ASM_TYPE
public static final org.springframework.cglib.core.HashCodeCustomizer HASH_ASM_TYPE
Type.hashCode()
is very expensive as it traverses full descriptor to calculate hash code. This customizer usesType.getSort()
as a hash code.
OBJECT_BY_CLASS
@Deprecated public static final org.springframework.cglib.core.Customizer OBJECT_BY_CLASS
已过时。this customizer might result in unexpected class leak since key object still holds a strong reference to the Object and class. It is recommended to have pre-processing method that would strip Objects and represent Classes as Strings
构造器详细资料
KeyFactory
protected KeyFactory()
方法详细资料
create
public static KeyFactory create(Class keyInterface)
create
public static KeyFactory create(Class keyInterface, org.springframework.cglib.core.Customizer customizer)
create
public static KeyFactory create(Class keyInterface, org.springframework.cglib.core.KeyFactoryCustomizer first, List<org.springframework.cglib.core.KeyFactoryCustomizer> next)
create
public static KeyFactory create(ClassLoader loader, Class keyInterface, org.springframework.cglib.core.Customizer customizer)
create
public static KeyFactory create(ClassLoader loader, Class keyInterface, org.springframework.cglib.core.KeyFactoryCustomizer customizer, List<org.springframework.cglib.core.KeyFactoryCustomizer> next)