what does error mean? warning: [static] static method should be qualified by type name, AnchorPane, instead of by an expression

StackOverflow https://stackoverflow.com/questions/14445623

  •  17-01-2022
  •  | 
  •  

Pregunta

I am getting this warning: warning: [static] static method should be qualified by type name, AnchorPane, instead of by an expression

here is my code:

public Chart(Vector<String[]> v, final Pane p, final AnchorPane ap){
    super();
    this.v = v;
    p.heightProperty().addListener(new ChangeListener<Number>() {
        public void changed(ObservableValue<? extends Number> ov,
        Number old_val, Number new_val) {
            draw();

            System.out.println(heightProperty().doubleValue()+" "+ap.getBottomAnchor(p));

        }
    });
}
¿Fue útil?

Solución

AnchorPane.getBottomAnchor() is a static method. Static methods are associated with a class, not an instance, and should therefore be called by their class name, not through a reference. The reason is to avoid confusion about which method is finally called, since static methods can not be overridden. See also https://stackoverflow.com/a/2629846/1611055 for some good additional information.

Try

System.out.println(heightProperty().doubleValue()+" "+AnchorPane.getBottomAnchor(p));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top