Package org.springframework.cglib.core

# Class 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 for `equals` and `hashCode` 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 named `newInstance`, which returns an `Object`. 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 the `newInstance` 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 keys `key1` and `key2` is only guaranteed if `key1.equals(key2)` and the keys were produced by the same factory.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`KeyFactory.Generator`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Customizer`
`CLASS_BY_NAME`
`static final HashCodeCustomizer`
`HASH_ASM_TYPE`
`Type.hashCode()` is very expensive as it traverses full descriptor to calculate hash code.
`static final Customizer`
`OBJECT_BY_CLASS`
Deprecated.
this customizer might result in unexpected class leak since key object still holds a strong reference to the Object and class.
`static final FieldTypeCustomizer`
`STORE_CLASS_AS_STRING`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`KeyFactory()`

## Method Summary

Modifier and Type
Method
Description
`static KeyFactory`
`create(Class keyInterface)`
`static KeyFactory`
`create(ClassLoader loader, Class keyInterface, Customizer customizer)`
`static KeyFactory`
`create(ClassLoader loader, Class keyInterface, KeyFactoryCustomizer customizer, List<KeyFactoryCustomizer> next)`
`static KeyFactory`
`create(Class keyInterface, Customizer customizer)`
`static KeyFactory`
`create(Class keyInterface, KeyFactoryCustomizer first, List<KeyFactoryCustomizer> next)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### CLASS_BY_NAME

public static final Customizer CLASS_BY_NAME

### STORE_CLASS_AS_STRING

public static final FieldTypeCustomizer STORE_CLASS_AS_STRING

### HASH_ASM_TYPE

public static final HashCodeCustomizer HASH_ASM_TYPE
`Type.hashCode()` is very expensive as it traverses full descriptor to calculate hash code. This customizer uses `Type.getSort()` as a hash code.

### OBJECT_BY_CLASS

@Deprecated public static final Customizer OBJECT_BY_CLASS
Deprecated.
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

## Constructor Details

### KeyFactory

protected KeyFactory()

## Method Details

### create

public static KeyFactory create(Class keyInterface)

### create

public static KeyFactory create(Class keyInterface, Customizer customizer)

### create

public static KeyFactory create(Class keyInterface, KeyFactoryCustomizer first, List<KeyFactoryCustomizer> next)

### create

public static KeyFactory create(ClassLoader loader, Class keyInterface, Customizer customizer)

### create

public static KeyFactory create(ClassLoader loader, Class keyInterface, KeyFactoryCustomizer customizer, List<KeyFactoryCustomizer> next)