Top Description Methods
com.google.auto.value

public @Interface AutoOneOf

extends Annotation
Annotations
@Retention:CLASS
@Target:TYPE
Imports
java.lang.annotation.ElementType, .Retention, .RetentionPolicy, .Target

Specifies that the annotated class is a one-of class, also known as a tagged union. An @AutoOneOf class is very similar to an @AutoValue class, in that its abstract methods define a set of properties. But unlike @AutoValue, only one of those properties is defined in any given instance.
@AutoOneOf(StringOrInteger.Kind.class)
public abstract class StringOrInteger {
  public enum Kind {STRING, INTEGER}

  public abstract Kind getKind();

  public abstract String string();
  public abstract int integer();

  public static StringOrInteger ofString(String s) {
    return AutoOneOf_StringOrInteger.string(s);
  }

  public static StringOrInteger ofInteger(int i) {
    return AutoOneOf_StringOrInteger.integer(i);
  }
}

String client(StringOrInteger stringOrInteger) {
  switch (stringOrInteger.getKind()) {
    case STRING:
      return "the string '" + stringOrInteger.string() + "'";
    case INTEGER:
      return "the integer " + stringOrInteger.integer();
  }
  throw new AssertionError();
}

@AutoOneOf is explained in more detail in the user guide.

Authors
Chris Nokleberg, Éamonn McManus

Method Summary

Modifier and TypeMethod and Description
public Class<? extends Enum<?>>
value()

Specifies an enum that has one entry per variant in the one-of.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public Class<? extends Enum<?>> value()

Specifies an enum that has one entry per variant in the one-of.