What is the reason for compile warning "static method declared final"?

George :

I have a constant class and I'm trying to set a batch number constant at run time with public static final String. My IDE is giving me a warning "static method declared final" and I'd like to know if I'm doing something incorrectly.

file gets value from Spring yml file.

private String file; (xxx-12345.txt)

public String getBatchNo() {
    return parseBatchNo(file);
}

public static final String parseBatchNo(String file) {
    return file.substring((file.lastIndexOf("-") + 1), (file.length() - 4));
}
user10367961 :

Static methods are not subject to overriding.

The final keyword hides the method. See the link in comments for more details.

Note that you should not rely on that behavior, although the language allows it. You should always invoke static methods as <class-name>.<method-name>.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=72472&siteId=1