Search code examples
javabinary-compatibility

Does removing the "final" keyword affect binary compatibility?


If I remove the final keyword from a method or other "thing", will users of my class have to recompile?


Solution

  • Technically, they won't have to recompile.

    I cannot think of any repercussions that can result from removing the final keyword from a method / attribute which may lead to loss in compatibility so it should not give you any problems.

    Tested with sample code and there were no runtime errors:

    public class Test2{
        public static final String test = "HELLO!";
    }
    
    public class Test {
        public static void main (String [] args) {
            System.out.println(Test2.test);
        }
    }
    
    1. Compiled Test.java
    2. Ran Test.java -> Output = "HELLO!"
    3. Modified Test2.java:

      public class Test2{
          public static String test = "HELLO!";
      }
      
    4. Compiled Test2.java

    5. Ran Test.java -> Output = "HELLO!"