Say, I have an existing code, which looks somewhat like this:
public class MyClass {
private AnotherClass obj;
// ... (class implementation)
public final getObj() { return obj; // It is this simple }
}
This class is implemented in a library, the versions of which are used by many different code bases.
I would like to remove the final
from the getObj()
method definition. I am aware of the fact that the method will no longer be inlined.
What other possible side effects could removing the final
keyword from getObj()
cause to its existing users?
As @Khelwood commented:
When a method is declared with final keyword, it is called a final method and it cannot be overridden and We must declare methods with final keyword for which we required to follow the same implementation throughout all the derived classes.
So, if you remove the final
keyword any implementation class can override this method functionality (as @Khelwood suggestion it is better to know why it was declared as final before removing it).