gabrielittner/auto-value-with

Add support for generic arguments

Closed this issue · 1 comments

I don't know how much work is needed to implement this feature, but it'd be great to be able to do something like this:

public abstract class PersistentModel<T extends PersistentModel<T>> {
    public abstract long id();
    public abstract T withId(long id);
}

@AutoValue
public abstract class MyModel extends PersistentModel<MyModel> {}

Which currently throws:

Error:(6, 17) error: @autovalue processor threw an exception: java.lang.IllegalArgumentException: withId() in [...].MyModel returns T, expected [...].MyModel

I'm looking into it.

As a temporary workaround you could override the with methods in MyModel with the concret type:

@AutoValue
public abstract class MyModel extends PersistentModel<MyModel> {
   @Override public abstract MyModel withId(long id);
}