79825483

Date: 2025-11-20 12:00:01
Score: 4
Natty:
Report link

Thank you @mernst!

I got this to work:

void startSomethingElse(@AccountIdParam long accountId, @BalanceParam long balance) {
    System.out.println("Account " + accountId + " balance " + balance);
}

void startOfSomething() {
    /*
     * either use:
     * @AccountIdParam long accountId = (@AccountIdParam long) 1;
     * or
     * @SuppressWarnings("assignment")
     */
    @SuppressWarnings("assignment")
    long accountId = 1;
    @SuppressWarnings("assignment")
    long balance = 100;
    startSomethingElse(balance, accountId);
}

And now I have these qualifiers:

@SubtypeOf({ParamUnknown.class})
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
public @interface AccountIdParam {}

@SubtypeOf({ParamUnknown.class})
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
public @interface BalanceParam {}

@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@SubtypeOf({AccountIdParam.class, BalanceParam.class})
public @interface ParamBottom {}

@DefaultQualifierInHierarchy
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@SubtypeOf({})
public @interface ParamUnknown {}

If my number of qualifiers grows, this line on ParamBottom where I list them will become cumbersome. Any advice on that?

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • User mentioned (1): @mernst
  • Self-answer (0.5):
  • Looks like a comment (1):
  • Low reputation (0.5):
Posted by: fritz