Package com.google.protobuf

# Class Descriptors.FieldDescriptor

java.lang.Object
com.google.protobuf.Descriptors.GenericDescriptor
com.google.protobuf.Descriptors.FieldDescriptor

All Implemented Interfaces:
  `com.google.protobuf.FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>`, `Comparable<Descriptors.FieldDescriptor>`

Enclosing class:
  `Descriptors`

public static final class Descriptors.FieldDescriptor extends Descriptors.GenericDescriptor implements Comparable<Descriptors.FieldDescriptor>, com.google.protobuf.FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>
Describes a field of a message type.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`Descriptors.FieldDescriptor.JavaType`
`static enum`
`Descriptors.FieldDescriptor.Type`

## Method Summary

Modifier and Type
Method
Description
`int`
`compareTo(Descriptors.FieldDescriptor other)`
Compare with another `FieldDescriptor`.
`Descriptors.OneofDescriptor`
`getContainingOneof()`
Get the field's containing oneof.
`Descriptors.Descriptor`
`getContainingType()`
Get the field's containing type.
`Object`
`getDefaultValue()`
Returns the field's default value.
`Descriptors.EnumDescriptor`
`getEnumType()`
For enum fields, gets the field's type.
`Descriptors.Descriptor`
`getExtensionScope()`
For extensions defined nested within message types, gets the outer type.
`Descriptors.FileDescriptor`
`getFile()`
Get the `FileDescriptor` containing this descriptor.
`String`
`getFullName()`
Get the field's fully-qualified name.
`int`
`getIndex()`
Get the index of this descriptor within its parent.
`Descriptors.FieldDescriptor.JavaType`
`getJavaType()`
Get the field's java type.
`String`
`getJsonName()`
Get the JSON name of this field.
`WireFormat.JavaType`
`getLiteJavaType()`
For internal use only.
`WireFormat.FieldType`
`getLiteType()`
For internal use only.
`Descriptors.Descriptor`
`getMessageType()`
For embedded message and group fields, gets the field's type.
`String`
`getName()`
Get the field's unqualified name.
`int`
`getNumber()`
Get the field's number.
`DescriptorProtos.FieldOptions`
`getOptions()`
Get the `FieldOptions`, defined in `descriptor.proto`.
`Descriptors.OneofDescriptor`
`getRealContainingOneof()`
Get the field's containing oneof, only if non-synthetic.
`Descriptors.FieldDescriptor.Type`
`getType()`
Get the field's declared type.
`boolean`
`hasDefaultValue()`
Returns true if the field had an explicitly-defined default value.
`boolean`
`hasPresence()`
Returns true if this field tracks presence, ie.
`MessageLite.Builder`
`internalMergeFrom(MessageLite.Builder to, MessageLite from)`
For internal use only.
`boolean`
`isExtension()`
Is this field an extension?
`boolean`
`isMapField()`
`boolean`
`isOptional()`
Is this field declared optional?
`boolean`
`isPackable()`
Can this field be packed? That is, is it a repeated primitive field?
`boolean`
`isPacked()`
Does this field have the `[packed = true]` option or is this field packable in proto3 and not explicitly set to unpacked?
`boolean`
`isRepeated()`
Is this field declared repeated?
`boolean`
`isRequired()`
Is this field declared required?
`boolean`
`legacyEnumFieldTreatedAsClosed()`
Determines if the given enum field is treated as closed based on legacy non-conformant behavior.
`boolean`
`needsUtf8Check()`
For internal use only.
`DescriptorProtos.FieldDescriptorProto`
`toProto()`
Convert the descriptor to its protocol message representation.
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Method Details

### getIndex

public int getIndex()
Get the index of this descriptor within its parent.

See Also:
  - `Descriptors.Descriptor.getIndex()`

### toProto

public DescriptorProtos.FieldDescriptorProto toProto()
Convert the descriptor to its protocol message representation.

Specified by:
  `toProto` in class `Descriptors.GenericDescriptor`

### getName

public String getName()
Get the field's unqualified name.

Specified by:
  `getName` in class `Descriptors.GenericDescriptor`

### getNumber

public int getNumber()
Get the field's number.

Specified by:
  `getNumber` in interface `com.google.protobuf.FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>`

### getFullName

public String getFullName()
Get the field's fully-qualified name.

Specified by:
  `getFullName` in class `Descriptors.GenericDescriptor`
See Also:
  - `Descriptors.Descriptor.getFullName()`

### getJsonName

public String getJsonName()
Get the JSON name of this field.

### getJavaType

public Descriptors.FieldDescriptor.JavaType getJavaType()
Get the field's java type. This is just for convenience. Every `FieldDescriptorProto.Type` maps to exactly one Java type.

### getLiteJavaType

public WireFormat.JavaType getLiteJavaType()
For internal use only.

Specified by:
  `getLiteJavaType` in interface `com.google.protobuf.FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>`

### getFile

public Descriptors.FileDescriptor getFile()
Get the `FileDescriptor` containing this descriptor.

Specified by:
  `getFile` in class `Descriptors.GenericDescriptor`

### getType

public Descriptors.FieldDescriptor.Type getType()
Get the field's declared type.

### getLiteType

public WireFormat.FieldType getLiteType()
For internal use only.

Specified by:
  `getLiteType` in interface `com.google.protobuf.FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>`

### needsUtf8Check

public boolean needsUtf8Check()
For internal use only.

### isMapField

public boolean isMapField()

### isRequired

public boolean isRequired()
Is this field declared required?

### isOptional

public boolean isOptional()
Is this field declared optional?

### isRepeated

public boolean isRepeated()
Is this field declared repeated?

Specified by:
  `isRepeated` in interface `com.google.protobuf.FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>`

### isPacked

public boolean isPacked()
Does this field have the `[packed = true]` option or is this field packable in proto3 and not explicitly set to unpacked?

Specified by:
  `isPacked` in interface `com.google.protobuf.FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>`

### isPackable

public boolean isPackable()
Can this field be packed? That is, is it a repeated primitive field?

### hasDefaultValue

public boolean hasDefaultValue()
Returns true if the field had an explicitly-defined default value.

### getDefaultValue

public Object getDefaultValue()
Returns the field's default value. Valid for all types except for messages and groups. For all other types, the object returned is of the same class that would returned by Message.getField(this).

### getOptions

public DescriptorProtos.FieldOptions getOptions()
Get the `FieldOptions`, defined in `descriptor.proto`.

### isExtension

public boolean isExtension()
Is this field an extension?

### getContainingType

public Descriptors.Descriptor getContainingType()
Get the field's containing type. For extensions, this is the type being extended, not the location where the extension was defined. See `getExtensionScope()`.

### getContainingOneof

public Descriptors.OneofDescriptor getContainingOneof()
Get the field's containing oneof.

### getRealContainingOneof

public Descriptors.OneofDescriptor getRealContainingOneof()
Get the field's containing oneof, only if non-synthetic.

### hasPresence

public boolean hasPresence()
Returns true if this field tracks presence, ie. does the field distinguish between "unset" and "present with default value."

This includes required, optional, and oneof fields. It excludes maps, repeated fields, and singular proto3 fields without "optional".

For fields where hasPresence() == true, the return value of msg.hasField() is semantically meaningful.

### getExtensionScope

public Descriptors.Descriptor getExtensionScope()
For extensions defined nested within message types, gets the outer type. Not valid for non-extension fields. For example, consider this `.proto` file:

       message Foo {
         extensions 1000 to max;
       }
       extend Foo {
         optional int32 baz = 1234;
       }
       message Bar {
         extend Foo {
           optional int32 moo = 4321;
         }
       }

Both `baz`'s and `moo`'s containing type is `Foo`. However, `baz`'s extension scope is `null` while `moo`'s extension scope is `Bar`.

### getMessageType

public Descriptors.Descriptor getMessageType()
For embedded message and group fields, gets the field's type.

### getEnumType

public Descriptors.EnumDescriptor getEnumType()
For enum fields, gets the field's type.

Specified by:
  `getEnumType` in interface `com.google.protobuf.FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>`

### legacyEnumFieldTreatedAsClosed

public boolean legacyEnumFieldTreatedAsClosed()
Determines if the given enum field is treated as closed based on legacy non-conformant behavior.

Conformant behavior determines closedness based on the enum and can be queried using `EnumDescriptor.isClosed()`.

Some runtimes currently have a quirk where non-closed enums are treated as closed when used as the type of fields defined in a `syntax = proto2;` file. This quirk is not present in all runtimes; as of writing, we know that:

- C++, Java, and C++-based Python share this quirk.
- UPB and UPB-based Python do not.
- PHP and Ruby treat all enums as open regardless of declaration.

Care should be taken when using this function to respect the target runtime's enum handling quirks.

### compareTo

public int compareTo(Descriptors.FieldDescriptor other)
Compare with another `FieldDescriptor`. This orders fields in "canonical" order, which simply means ascending order by field number. `other` must be a field of the same type. That is, `getContainingType()` must return the same `Descriptor` for both fields.

Specified by:
  `compareTo` in interface `Comparable<Descriptors.FieldDescriptor>`
Returns:
  negative, zero, or positive if `this` is less than, equal to, or greater than `other`, respectively

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### internalMergeFrom

public MessageLite.Builder internalMergeFrom(MessageLite.Builder to, MessageLite from)
For internal use only. This is to satisfy the FieldDescriptorLite interface.

Specified by:
  `internalMergeFrom` in interface `com.google.protobuf.FieldSet.FieldDescriptorLite<Descriptors.FieldDescriptor>`