Overview | Package | Class | Use | Tree | Deprecated | Index
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javassist
Class CtField

    java.lang.Object
      |
      +--javassist.CtMember
            |
            +--javassist.CtField

public class CtField
extends CtMember

An instance of CtField represents a field.

See Also:
  `CtClass.getDeclaredFields()`

Nested Class Summary
`static class` | `CtField.Initializer` Instances of this class specify how to initialize a field.

Constructor Summary
`CtField(CtClass type, java.lang.String name, CtClass declaring)` Creates a `CtField` object.
`CtField(CtField src, CtClass declaring)` Creates a copy of the given field.

Method Summary
`byte[]` | `getAttribute(java.lang.String name)` Obtains an attribute with the given name.
`CtClass` | `getDeclaringClass()` Returns the class declaring the field.
`FieldInfo` | `getFieldInfo()` Returns the FieldInfo representing the field in the class file.
`FieldInfo` | `getFieldInfo2()` Undocumented method.
`int` | `getModifiers()` Returns the encoded modifiers of the field.
`java.lang.String` | `getName()` Returns the name of the field.
`CtClass` | `getType()` Returns the type of the field.
`static CtField` | `make(java.lang.String src, CtClass declaring)` Compiles the given source code and creates a field.
`void` | `setAttribute(java.lang.String name, byte[] data)` Adds an attribute.
`void` | `setModifiers(int mod)` Sets the encoded modifiers of the field.
`void` | `setName(java.lang.String newName)` Changes the name of the field.
`void` | `setType(CtClass clazz)` Sets the type of the field.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CtField

    public CtField(CtClass type,
                   java.lang.String name,
                   CtClass declaring)
            throws CannotCompileException

  Creates a `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:
  `CtClass.addField(CtField)`, `CtNewMethod.getter(String,CtField)`, `CtNewMethod.setter(String,CtField)`, `CtField.Initializer`

### CtField

    public CtField(CtField src,
                   CtClass declaring)
            throws CannotCompileException

  Creates a copy of the given field. 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:
  `src` - the original field
  `declaring` - the class to which the field will be added.
See Also:
  `CtNewMethod.getter(String,CtField)`, `CtNewMethod.setter(String,CtField)`, `CtField.Initializer`

Method Detail

### make

    public static CtField make(java.lang.String src,
                               CtClass declaring)
                        throws CannotCompileException

  Compiles the given source code and creates a field. Examples of the source code are:

       "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.
    `CannotCompileException`

### getFieldInfo

    public FieldInfo getFieldInfo()

  Returns the FieldInfo representing the field in the class file.

### getFieldInfo2

    public FieldInfo getFieldInfo2()

  Undocumented method. Do not use; internal-use only.

### getDeclaringClass

    public CtClass getDeclaringClass()

  Returns the class declaring the field.

  Overrides:
    `getDeclaringClass` in class `CtMember`

### getName

    public java.lang.String getName()

  Returns the name of the field.

  Specified by:
    `getName` in class `CtMember`

### setName

    public void setName(java.lang.String newName)

  Changes the name of the field.

### getModifiers

    public int getModifiers()

  Returns the encoded modifiers of the field.

  Specified by:
    `getModifiers` in class `CtMember`
  Returns:
    modifiers encoded with `javassist.Modifier`.
  See Also:
    `Modifier`

### setModifiers

    public void setModifiers(int mod)

  Sets the encoded modifiers of the field.

  Specified by:
    `setModifiers` in class `CtMember`
  See Also:
    `Modifier`

### getType

    public CtClass getType()
                    throws NotFoundException

  Returns the type of the field.

    `NotFoundException`

### setType

    public void setType(CtClass clazz)

  Sets the type of the field.

### getAttribute

    public byte[] getAttribute(java.lang.String name)

  Obtains an attribute with the given name. If that attribute is not found in the class file, this method returns null.

  Specified by:
    `getAttribute` in class `CtMember`
  Parameters:
    `name` - attribute name

### setAttribute

    public void setAttribute(java.lang.String name,
                             byte[] data)

  Adds an attribute. The attribute is saved in the class file.

  Specified by:
    `setAttribute` in class `CtMember`
  Parameters:
    `name` - attribute name
    `data` - attribute value

Overview | Package | Class | Use | Tree | Deprecated | Index
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Javassist, a Java-bytecode translator toolkit. Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.