Registration is a simple interface, which is quite easy to get wrong due to simple lamdas not being idempotent:
Registration reg = () -> { // not idempotent! }; reg.close() // executes the block reg.close() // also executes the block!
Current way of doing this is quite verbose:
var reg = AbstractRegistration() { @Override protected void removeRegistration() { // idempotent } }; reg.close() // executes the block reg.close() // does nothing
Add Registration.of(Runnable) utility method which wraps a callback and executes it just once, backed by AbstractRegistration logic. This allows users to use lambdas (and method references) and wrap them with a guard:
var reg = Registration.of(() -> { // idempotent }); reg.close() // executes the block reg.close() // does nothing
The same patterns applies to ObjectRegistration and ListenerRegistration.