Towards cleaner nesting

Kasper Nielsen kasperni at gmail.com
Wed Jan 8 15:11:17 UTC 2020


> On 1/7/20 12:30 PM, Brian Goetz wrote:
> >
> > Goals:
> >  - Anything (class, interface, record, enum, method) can be nested in
> > anything;
>
> Does "Anything" include annotation types?

That would be nice.

Every respectable dependency injection framework has some kind of
@Named("name") annotation. And every one of them has a companioning
utility class that allows one to create one from a String a.la.

class Names {
   public static Named of(String names);
}

Because static methods are not allowed on annotations.

See, for example
https://github.com/google/guice/blob/master/core/src/com/google/inject/name/Named.java
https://github.com/google/guice/blob/master/core/src/com/google/inject/name/Names.java

Maybe even allow default methods, to make up for the lack of support for
non-constant expressions:

@interface Cron {
   String value();

   default CronExpression cron() {
     return CronExpression.parse(value());
   }
}

/ Kasper


More information about the amber-spec-observers mailing list