0

I'm trying to force class SomeImpl to declare an annotation @SomeAnnotation if it is implementing interface SomeInterface. Solution can modify SomeInterface declaration.

public interface SomeInterface {}

public class SomeImpl implements SomeInterface -> compilation error

@SomeAnnotation
public class SomeInterfaceImpl implements SomeInterface -> compilation ok

Use case: I'm using objects implementing SomeInterface in a method (not written by me, it's an external library) that always read the annotation @SomeAnnotation and it can not be empty or default.

Thanks!

italktothewind
  • 1,950
  • 2
  • 28
  • 55

1 Answers1

-1

It seems this can only be done using annotations processor (https://docs.oracle.com/javase/7/docs/api/javax/annotation/processing/Processor.html).

italktothewind
  • 1,950
  • 2
  • 28
  • 55