AnnotationDefault_attribute.
For example, if you declare the following annotation type:
@interface Author {
String name() default "Shakespeare";
int age() default 99;
}
The defautl values of name and age
are stored as annotation default attributes in Author.class.
The following code snippet obtains the default value of name:
ClassPool pool = ...
CtClass cc = pool.get("Author");
CtMethod cm = cc.getDeclaredMethod("age");
MethodInfo minfo = cm.getMethodInfo();
AnnotationDefaultAttribute ada
= (AnnotationDefaultAttribute)
minfo.getAttribute(AnnotationDefaultAttribute.tag);
MemberValue value = ada.getDefaultValue()); // default value of age
If the following statement is executed after the code above, the default value of age is set to 80:
ada.setDefaultValue(new IntegerMemberValue(minfo.getConstPool(), 80));
AnnotationsAttribute, javassist.bytecode.annotation.MemberValue
| Modifier and Type | Field and Description |
|---|---|
| public static final String | tag
The name of the |
| Access | Constructor and Description |
|---|---|
| public | AnnotationDefaultAttribute(ConstPool
constant pool cp, byte[] the contents of this attribute. It does not
include info)attribute_name_index or
attribute_length.Constructs an |
| public | AnnotationDefaultAttribute(ConstPool
constant pool cp)Constructs an empty |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public AttributeInfo | |
| public MemberValue | |
| pack-priv void | |
| pack-priv void | |
| public void | setDefaultValue(MemberValue
the new value. value)Changes the default value represented by this attribute. |
| public String |
| tag | back to summary |
|---|---|
| public static final String tag The name of the | |
| AnnotationDefaultAttribute | back to summary |
|---|---|
| public AnnotationDefaultAttribute(ConstPool cp, byte[] info) Constructs an
| |
| AnnotationDefaultAttribute | back to summary |
|---|---|
| public AnnotationDefaultAttribute(ConstPool cp) Constructs an empty
| |
| AnnotationDefaultAttribute | back to summary |
|---|---|
pack-priv AnnotationDefaultAttribute(ConstPool cp, int n, DataInputStream in) throws IOException
| |
| copy | back to summary |
|---|---|
| public AttributeInfo copy(ConstPool newCp, Map<String, String> classnames) Overrides javassist. Copies this attribute and returns a new copy.
| |
| getDefaultValue | back to summary |
|---|---|
| public MemberValue getDefaultValue() Obtains the default value represented by this attribute. | |
| renameClass | back to summary |
|---|---|
| pack-priv void renameClass(String oldname, String newname) Overrides javassist.
| |
| renameClass | back to summary |
|---|---|
| pack-priv void renameClass(Map<String, String> classnames) Overrides javassist.
| |
| setDefaultValue | back to summary |
|---|---|
| public void setDefaultValue(MemberValue value) Changes the default value represented by this attribute.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this object.
| |