After much downvotes and some googling,
Thanks to Jaroslaw Pawlak, I found the answer to my question.
The answer was to completely ditch the class shown in my question and to replace it with :
List of consumers :
List<Consumer<String>> inputReceivers = new ArrayList<Consumer<String>>();
Now to add consumers :
public void addReceiver(Consumer<String> receiver) {
inputReceivers.add(receiver);
}
And triggered on event :
for (Consumer<String> a : inputReceivers) {
a.accept("some string data");
}
That's all! No need to implement any interface or extend abstract class, this works well with methods.
I can do something like this :
addReceiver(s -> {
if (!StringUtils.isAllBlank(s)) {
// deal with string s
}
});
Almost magic!