Alright, so as discussed I will make weak references the default for event listeners, while adding an annotation which enforces a regular reference.
I have implemented it and it behaves exactly as I thought:
I can detect the @SuppressWarnings("unused-return")
on the method and thus hide the warning, but simultaneously get an "Unsupported…
The check is not the problem. The problem is, that Eclipse and probably other compilers as well would warn the user about the unhandled warning token, which would leave the user with yet another…
This only proves that the need for garbage collection is actually negligibe as most event listeners have the same lifetime as the entire application.
If a listener with a restricted lifetime…
Agreed, but how would you go about suppressing the warning? Define a custom warning string to use in @SuppressWarnings
, or just introduce parameters for the processor? I will have a look into that.
That's a good idea, however we have to find a way of suppressing the warning if a non-void return type actually has to be used, for example when retrofitting code to utilize event handling.
For that reason, EventBus#removeListener
exists. If we no longer need a listener, we remove it and then it's available for garbage collection.
If, however, a dedicated event listener is defined…