Name (Java SE 26 & JDK 26)
Description: declaration: module: java.compiler, package: javax.lang.model.element, interface: Name
Keywords: javax.lang.model.element.Name interface

# Interface Name

All Superinterfaces:
  `CharSequence`

public interface Name extends CharSequence
An immutable sequence of characters. When created by the same implementation, objects implementing this interface must obey the general equals contract when compared with each other. Therefore, `Name` objects from the same implementation are usable in collections while `Name`s from different implementations may not work properly in collections.

An empty `Name` has a length of zero.

In the context of annotation processing, the guarantees for "the same" implementation must include contexts where the API mediated side effects of processors could be visible to each other, including successive annotation processing rounds.

Since:
  1.6
See Also:
  - `Elements.getName(CharSequence)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `contentEquals(CharSequence cs)`
  Compares this name to the specified `CharSequence`.
  `boolean`
  `equals(Object obj)`
  Returns `true` if the argument represents the same name as `this`, and `false` otherwise.
  `int`
  `hashCode()`
  Obeys the general contract of `Object.hashCode`.

  ### Methods declared in interface CharSequence

  `charAt, chars, codePoints, getChars, isEmpty, length, subSequence, toString`
  Modifier and Type
  Method
  Description
  `char`
  `charAt(int index)`
  Returns the `char` value at the specified index.
  `default IntStream`
  `chars()`
  Returns a stream of `int` zero-extending the `char` values from this sequence.
  `default IntStream`
  `codePoints()`
  Returns a stream of code point values from this sequence.
  `default void`
  `getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)`
  Copies characters from this sequence into the given destination array.
  `default boolean`
  `isEmpty()`
  Returns `true` if this character sequence is empty.
  `int`
  `length()`
  Returns the length of this character sequence.
  `CharSequence`
  `subSequence(int start, int end)`
  Returns a `CharSequence` that is a subsequence of this sequence.
  `String`
  `toString()`
  Returns a string containing the characters in this sequence in the same order as this sequence.

- ## Method Details

  - ### equals

    boolean equals(Object obj)
    Returns `true` if the argument represents the same name as `this`, and `false` otherwise.

    Note that the identity of a `Name` is a function both of its content in terms of a sequence of characters as well as the implementation which created it.

    Overrides:
      `equals` in class `Object`
    Parameters:
      `obj` - the object to be compared with this element
    Returns:
      `true` if the specified object represents the same name as this
    See Also:
      - `Element.equals(Object)`

  - ### hashCode

    int hashCode()
    Obeys the general contract of `Object.hashCode`.
    Overrides:
      `hashCode` in class `Object`
    Returns:
      a hash code value for this object
    See Also:
      - `equals(Object)`

  - ### contentEquals

    boolean contentEquals(CharSequence cs)
    Compares this name to the specified `CharSequence`. The result is `true` if and only if this name represents the same sequence of `char` values as the specified sequence.
    Parameters:
      `cs` - The sequence to compare this name against
    Returns:
      `true` if this name represents the same sequence of `char` values as the specified sequence, `false` otherwise
    See Also:
      - `String.contentEquals(CharSequence)`