Vaadin 8 - Remove Listener after one time Execution using Registration

I am wondering how I can use something like a one-time listener:

Registration registration = component.addAttachListener((AttachListener) event -> {
    registration.remove();
    // Execute my code
});

My IDE is complaining that “registration” might not be initialized.

Hi,
a workaround could be the following

AtomicReference<Registration> registrationHolder = new AtomicReference<>();
registrationHolder.set(component.addAttachListener((AttachListener) event -> {
    registrationHolder.get().remove();
    registrationHolder.set(null);
    // Execute my code
});

HTH
Marco