Problem overriding setReadOnly

An interesting issue. Eclipse won’t allow me to do this:

var test = new TextField() {
    @Override
    public void setReadOnly(boolean readOnly) {
        super.setReadOnly(readOnly);
        // ^-- Cannot directly invoke the abstract method HasValue.setReadOnly(boolean)
    }
};

Issue is that TextField implements both HasValue and HasValueAndElement, and the method has a default implementation in the latter interface…

So, Eclipse gets confused. Not sure about java as such.
I can get around it by instead of calling super, just copy the 1 line of code it has, but that is super ugly.

Any better suggestions?

Eclipse problem that’s already known: More information here: Vaadin 24.1.10 -> 24.2.1 update is causing inheritance problems in CustomField · Issue #5650 · vaadin/flow-components · GitHub

with a workaround by @sissbruecker

3 Likes