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

user1958884 picture user1958884 · Jan 21, 2013 · Viewed 10k times · Source

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));

        }
    });
}

Answer

Andreas Fester picture Andreas Fester · Jan 21, 2013

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));