java.util.Map s.
The reason for having a separate key class instead of
directly using Class as key is mostly
to allow for redefining hashCode method --
for some strange reason, Class does not
redefine Object#hashCode and thus uses identity
hash, which is pretty slow. This makes key access using
Class unnecessarily slow.
Note
since class is not strictly immutable, caller must know what it is doing, if changing field values.
| Modifier and Type | Field and Description |
|---|---|
| private Class | |
| private String | |
| private int | _flags
Additional discriminator flags that may be used to allow variations for same class. |
| private int | _hashCode
Let's cache hash code straight away, since we are almost certain to need it. |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | equals(Object
the reference object with which to compare. o)Overrides java. Indicates whether some other object is "equal to" this one. |
| public int | |
| public String | |
| public ClassKey |
| _class | back to summary |
|---|---|
| private Class<?> _class | |
| _className | back to summary |
|---|---|
| private String _className | |
| _flags | back to summary |
|---|---|
| private int _flags Additional discriminator flags that may be used to allow variations for same class.
| |
| _hashCode | back to summary |
|---|---|
| private int _hashCode Let's cache hash code straight away, since we are almost certain to need it. | |
| ClassKey | back to summary |
|---|---|
| public ClassKey() | |
| ClassKey | back to summary |
|---|---|
| public ClassKey(Class<?> clz, int flags) | |
| equals | back to summary |
|---|---|
| public boolean equals(Object o) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes. | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| with | back to summary |
|---|---|
| public ClassKey with(Class<?> clz, int flags) | |