79470427

Date: 2025-02-26 16:35:33
Score: 3.5
Natty:
Report link

I don't really understand the downvotes for user1418199's answer. It doesn't answer the original question directly, but gives more than enough information to do what the OP is trying to do.

AFAIK the OP tries to avoid copy-pasting code, as suggested at the end by this answer.

If I were him, I'd follow this approach:

  1. Code an abstract BaseUser that is NOT annotated as AutoValue. Nor its builder. Put this all common fields.
  2. Code an AutoValue User class extending from BaseUser. Make its builder extend from BaseUser.Builder (for this, see the aforementioned correct answer from user1418199). This class will be mostly empty, only a few "builder" methods needed.
  3. Finally, add another AutoValue Customer class extending also from BaseUser. Add here the extra fields applicable only to Customer. Make its builder extend from BaseUser.Builder and add builder methods for the extra fields.

With this approach, no, we're not extending an AutoValue class, as requested by the OP, but we're successfully using AutoValue while avoiding copy-pasting.

Reasons:
  • RegEx Blacklisted phrase (2): downvote
  • Long answer (-1):
  • No code block (0.5):
  • User mentioned (1): user1418199
  • Low reputation (1):
Posted by: victama