Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error when using "withFactoryMethod" on generic pojo #93

Closed
mkarneim opened this issue Nov 29, 2014 · 0 comments
Closed

Compilation error when using "withFactoryMethod" on generic pojo #93

mkarneim opened this issue Nov 29, 2014 · 0 comments
Assignees
Labels
Milestone

Comments

@mkarneim
Copy link
Owner

The compiler will issue an error when it tries to compile a generic pojo annotated with
@GeneratePojoBuilder(withFactoryMethod="*").

For example:

@GeneratePojoBuilder(withFactoryMethod="*")
public class Container<T> {
  private T value;

  public T getValue() {
    return value;
  }

  public void setValue(T value) {
    this.value = value;
  }
}

When compiling this, I get the following error:

error: non-static type variable T cannot be referenced from a static context

The reason is, that the generated factory method does not declare the generic type variable T. It can't just reuse the one declared on class level.

public class ContainerBuilder<T extends Object>
    implements Cloneable {
[...]
  public static ContainerBuilder<T> container() {
    return new ContainerBuilder();
  } 

Instead we have to introduce a new one and mapping it.

  public static <T extends Object> ContainerBuilder<T> container() {
    return new ContainerBuilder<T>();
  }
@mkarneim mkarneim added the Bug label Nov 29, 2014
@mkarneim mkarneim modified the milestones: 3.4.0, 3.3.1 Dec 5, 2014
@mkarneim mkarneim self-assigned this Dec 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant