How to remove listener from Clipboard manager when using the method reference operator?

41 views Asked by At

I have started using the method reference operator :: in java. I am basically adding a Clipboard listener to the clipboard manager like this:

    this.clipboardManager.addPrimaryClipChangedListener(this::doSomething);

but since this way I don't get a reference to the listener I have just added, how would I remove the listener then?

Like this?

    this.clipboardManager.removePrimaryClipChangedListener(this::doSomething);
1

There are 1 answers

1
mdwheaton On

You're adding an anonymous class and then trying to remove a separately created anonymous class, that doesn't exist.