When I add an event listener using a lambda that calls an overridable method in the constructor, I get a warning. If I use a method reference, I don't get any warnings about overridable methods or leaking this. Should I avoid method references in the constructor or is it safe?
Here's a simple example:
public class SomeClass {
public SomeClass(SomeObj obj) {
obj.addListener(this::handleEvent); // no warnings, is it really safe?
obj.addListener((event) -> handleEvent(event)); // warning about overridable method in constructor
}
private void handleEvent(Event event) {
event.doSomething(someMethod());
}
private void someMethod() {
...
}
}