Java `final` method: what does it promise?

In a Java class a method can be defined to be final, to mark that this method may not be overridden:

public class Thingy {
    public Thingy() { ... }
    public int operationA() {...}
    /** this method does @return That and is final. */
    public final int getThat() { ...}
}

That's clear, and it may be of some use to protect against accidental overriding, or maybe performance — but that's not my question.

My question is: From an OOP point of view I understood that, by defining a method final the class designer promises this method will always work as described, or implied. But often this may be outside the influence of the class author, if what the method is doing is more complicated then just delivering a property.

The syntactic constraint is clear to me, but what is the implication in the OOP sense? Is final used correctly in this sense by most class authors?

What kind of "contract" does a final method promise?

134
задан Reinstate Monica 22 August 2014 в 09:19
поделиться