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


Question

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

        }
    });
}
1
2
1/21/2013 7:28:18 PM

Accepted Answer

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));
7
5/23/2017 12:09:02 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon