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
  •  | 
  •  

문제

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

        }
    });
}
도움이 되었습니까?

해결책

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));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top