Top Description Fields Constructors Methods
org.springframework.cglib.core

public Class DefaultNamingPolicy

extends Object
implements NamingPolicy
Class Inheritance
All Implemented Interfaces
org.springframework.cglib.core.NamingPolicy

The default policy used by AbstractClassGenerator. Generates names such as

org.springframework.cglib.Foo$$EnhancerByCGLIB$$38272841

This is composed of a prefix based on the name of the superclass, a fixed string incorporating the CGLIB class responsible for generation, and a hashcode derived from the parameters used to create the object. If the same name has been previously been used in the same ClassLoader, a suffix is added to ensure uniqueness.

Field Summary

Modifier and TypeField and Description
public static final DefaultNamingPolicy
private static final boolean
STRESS_HASH_CODE

This allows to test collisions of key.hashCode().

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Implements org.springframework.cglib.core.NamingPolicy.equals.

The NamingPolicy in use does not currently, but may in the future, affect the caching of classes generated by AbstractClassGenerator, so this is a reminder that you should correctly implement equals and hashCode to avoid generating too many classes.
public String
getClassName(String
a dotted-name chosen by the generating class (possibly to put the generated class in a particular package)
prefix
,
String
the fully-qualified class name of the generating class (for example "org.springframework.cglib.Enhancer")
source
,
Object
A key object representing the state of the parameters; for caching to work properly, equal keys should result in the same generated class name. The default policy incorporates key.hashCode() into the class name.
key
,
Predicate
a predicate that returns true if the given classname has already been used in the same ClassLoader.
names
)

Implements org.springframework.cglib.core.NamingPolicy.getClassName.

Choose a name for a generated class.
protected String
getTag()

Returns a string which is incorporated into every generated class name.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
public static final DefaultNamingPolicy INSTANCE
STRESS_HASH_CODEback to summary
private static final boolean STRESS_HASH_CODE

This allows to test collisions of key.hashCode().

Constructor Detail

DefaultNamingPolicyback to summary
public DefaultNamingPolicy()

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Implements org.springframework.cglib.core.NamingPolicy.equals.

Doc from org.springframework.cglib.core.NamingPolicy.equals.

The NamingPolicy in use does not currently, but may in the future, affect the caching of classes generated by AbstractClassGenerator, so this is a reminder that you should correctly implement equals and hashCode to avoid generating too many classes.

Parameters
o:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getClassNameback to summary
public String getClassName(String prefix, String source, Object key, Predicate names)

Implements org.springframework.cglib.core.NamingPolicy.getClassName.

Doc from org.springframework.cglib.core.NamingPolicy.getClassName.

Choose a name for a generated class.

Parameters
prefix:String

a dotted-name chosen by the generating class (possibly to put the generated class in a particular package)

source:String

the fully-qualified class name of the generating class (for example "org.springframework.cglib.Enhancer")

key:Object

A key object representing the state of the parameters; for caching to work properly, equal keys should result in the same generated class name. The default policy incorporates key.hashCode() into the class name.

names:Predicate

a predicate that returns true if the given classname has already been used in the same ClassLoader.

Returns:String

the fully-qualified class name

Annotations
@Override
getTagback to summary
protected String getTag()

Returns a string which is incorporated into every generated class name. By default returns "ByCGLIB"

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override