javassist
public class CtField extends CtMember
See Also: getDeclaredFields
Nested Class Summary | |
---|---|
abstract static class | CtField.Initializer
Instances of this class specify how to initialize a field.
|
Constructor Summary | |
---|---|
CtField(CtClass type, String name, CtClass declaring)
Creates a CtField object.
| |
CtField(CtField src, CtClass declaring)
Creates a copy of the given field.
|
Method Summary | |
---|---|
Object[] | getAnnotations()
Returns the annotations associated with this field.
|
byte[] | getAttribute(String name)
Obtains an attribute with the given name.
|
Object[] | getAvailableAnnotations()
Returns the annotations associated with this field.
|
Object | getConstantValue()
Returns the value of this field if it is a constant field.
|
CtClass | getDeclaringClass()
Returns the class declaring the field. |
FieldInfo | getFieldInfo()
Returns the FieldInfo representing the field in the class file. |
FieldInfo | getFieldInfo2()
Returns the FieldInfo representing the field in the class
file (read only).
|
int | getModifiers()
Returns the encoded modifiers of the field.
|
String | getName()
Returns the name of the field. |
String | getSignature()
Returns the character string representing the type of the field.
|
CtClass | getType()
Returns the type of the field. |
static CtField | make(String src, CtClass declaring)
Compiles the given source code and creates a field.
|
void | setAttribute(String name, byte[] data)
Adds an attribute. |
void | setModifiers(int mod)
Sets the encoded modifiers of the field.
|
void | setName(String newName)
Changes the name of the field. |
void | setType(CtClass clazz)
Sets the type of the field. |
String | toString()
Returns a String representation of the object. |
CtField
object.
The created field must be added to a class
with CtClass.addField()
.
An initial value of the field is specified
by a CtField.Initializer
object.
If getter and setter methods are needed,
call CtNewMethod.getter()
and
CtNewMethod.setter()
.
Parameters: type field type name field name declaring the class to which the field will be added.
See Also: addField getter setter Initializer
CtClass.addField()
.
An initial value of the field is specified
by a CtField.Initializer
object.
If getter and setter methods are needed,
call CtNewMethod.getter()
and
CtNewMethod.setter()
.
Parameters: src the original field declaring the class to which the field will be added.
See Also: getter setter Initializer
Returns: an array of annotation-type objects.
Since: 3.1
See Also: getAvailableAnnotations
Note that an attribute is a data block specified by the class file format. See AttributeInfo.
Parameters: name attribute name
Returns: an array of annotation-type objects.
Since: 3.3
See Also: getAnnotations
String
type. Otherwise, it returns null
.
A constant field is static
and final
.
Returns: a Integer
, Long
, Float
,
Double
, Boolean
,
or String
object
representing the constant value.
null
if it is not a constant field
or if the field type is not a primitive type
or String
.
getFieldInfo()
.
The FieldInfo
object obtained by this method
is read only. Changes to this object might not be reflected
on a class file generated by toBytecode()
,
toClass()
, etc in CtClass
.
This method is available even if the CtClass
containing this field is frozen. However, if the class is
frozen, the FieldInfo
might be also pruned.
See Also: getFieldInfo isFrozen prune
See Also: Modifier
getSignature()
returns the same string.
Note that the returned string is not the type signature
contained in the SignatureAttirbute
. It is
a descriptor. To obtain a type signature, call the following
methods:
getFieldInfo().getAttribute(SignatureAttribute.tag)
See Also: Descriptor SignatureAttribute
"public String name;" "public int k = 3;"
Note that the source code ends with ';'
(semicolon).
Parameters: src the source text. declaring the class to which the created field is added.
Note that an attribute is a data block specified by the class file format. See AttributeInfo.
Parameters: name attribute name data attribute value
See Also: Modifier