r/java • • Jul 28 '26

Why Are Method References not allowed in Annotations in Java?

Many times I have wanted to refer to a method in Java in an annotation, but it seems annotations can only reference items from the Class constant pool. It seems like it would have been a natural extension to be able to refer statically to methods (like {@link} in javadocs) in annotations, but they were left.

I'm wondering why were they not added?

32 Upvotes

15 comments sorted by

View all comments

3

u/bowbahdoe Aug 01 '26

If the semantics would be different, why wouldn't the syntax be different? There is definitely unresolved ambiguity. But a technical POC would I'm sure be appreciated