Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a few possible breaks I can see</p> <ul> <li>you assume that clients will use a new overloaded method, but they don't because the code hasn't been recompiled.</li> <li>you add a method which the client already had which does something different.</li> <li>you add a method which means their subclasses break when recompiled. IMHO This is desirable.</li> <li>you change the return type, method name or parameters types which will cause an Error at runtime.</li> <li>you swap parameters of the same type. This is possibly the worst and most subtle bug. ;)</li> </ul> <p>IMHO, It's the subtle problems which are more likely to cause you grief. However, I wouldn't assume that simply adding a method will break the code and I wouldn't assume that if a client's code isn't getting runtime error means they are using the latest version of anything. ;)</p> <hr> <p>If I compile this code</p> <pre><code>public interface MyInterface { void method1(); // void method2(); } public class Main implements MyInterface { @Override public void method1() { System.out.println("method1 called"); } public static void main(String... args) { new Main().method1(); } } </code></pre> <p>it prints</p> <pre><code>method1 called </code></pre> <p>I then uncomment method2() and recompile just the interface. This means the interface has a method the <code>Main</code> doesn't implement. Yet when I run it without recompiling <code>Main</code> I get</p> <pre><code>method1 called </code></pre> <hr> <p>If I have</p> <pre><code>public class Main implements MyInterface { public void method1() { System.out.println("method1 called"); } public void method2() { System.out.println("method2 called"); } public static void main(String... args) { new Main().method1(); } } </code></pre> <p>and I run with <code>// method2()</code> commented out, I don't have a problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload