Using @AutoValue with nested classes gives a "cannot find symbol" error

2022-09-04 01:20:11

When trying to use @AutoValue with nested classes:

public class Nested {
  @AutoValue
  public static abstract class Example {
    public static Example create(String name, int integer) {
      return new AutoValue_Example(name, integer);
    }
    public abstract String name();
    public abstract int integer();
  }
}

I get a compiler error for . Any ideas on what I'm doing wrong?cannot find symbolAutoValue_Example


答案 1

When your class is nested like this, the generated AutoValue class would be named . As stated in the docs:AutoValue_Nested_Example

Nesting

For a nested abstract value type called Foo.Bar.Qux, the generated implementation class is named AutoValue_Foo_Bar_Qux.


答案 2

The inner class (in case it is static) is generated in a separated source file named 'AutoValue_outerClass_innerClass'


推荐