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

2

14

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 cannot find symbol for AutoValue_Example. Any ideas on what I'm doing wrong?

Synge answered 26/3, 2014 at 18:21 Comment(1)
Is the AutoValue type on the classpath at compilation time.Antipas
S
23

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

Nesting

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

Suffer answered 26/3, 2014 at 18:29 Comment(3)
Wouldn't the Example class also need to be static? (BTW, the create method also lacks the static keyword)Phelgon
Yes, generally speaking.Suffer
FYI: I just edited the question to add the missing static keywords.Phelgon
S
0

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

Spotted answered 13/3, 2019 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.