Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marker interface or annotations?

I need to mark some classes as Invokable - just to tell I can invoke methods of the class using reflection. But I don't like the idea of having an empty interface just for this purpose. Can this be done with annotations and still preserve behaviour on the example below? (I have never created my own annotations, so I'm not familiar with them in depth)

Example

class ClassOne implements Invokable {
}

class ClassTwo implements Invokable {
}

void someMethod(Invokable inv) {
}
like image 865
user219882 Avatar asked Jan 26 '26 01:01

user219882


1 Answers

Because of someMethod, you can't use annotations. Perhaps later you'll find that Invokable may need useful methods anyway.

Also, be sure to check out already existing interfaces like Callable, Future etc. before you re-invent the wheel.

like image 96
Ingo Avatar answered Jan 28 '26 21:01

Ingo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!