I’m interested in doing something like this:
public interface Foo {
public static "abstract" Bar SOME_BAR; // subclasses define one of these
}
and
public interface Foo {
public static "abstract" Baz buildABas(...); // subclasses define this method
}
without the statics, this is OOP 101, but it can’t be done in standard oop java. I wonder if there’s an annotation that would ensure this behavior?
edit:
i’m interested in specifying a set of options which define how to set things for “configurable” objects. this could be command-line flags, etc.
I’m guessing what you’re wanting is to have a method like
and you want to ensure that
clazzhas a methodpublic static void foo().I thought about this a while and none of the techniques that come to mind will get you there. You can use an
AnnotationProcessorto ensure that any classes annotated with a certain annotation have a specific method or what have you (and generate a compile error if they don’t) but there’s no way to ensure (at compile time) thatClassarguments passed tocallFoo(Class<?> clazz)are annotated with your annotation.Here’s an AnnotationProcessor that gets you halfway there:
Ultimately, I would suggest you either allow it to be something enforced at runtime or your redesign your code so you don’t need to use static methods.