Java – Could changing the return type from void to string introduce breaking changes

interfacesjavarefactoring

This SDK have an interface like this:

public interface Contract {
     void update(..);
     void action(..);
     void delete(..);
}

Now, we need to change it to something like this:

public interface Contract {
     String update(..);
     String action(..);
     String delete(..);
}

The interface is implemented internally by the SDK; that is not a problem. The question scope is beyond the case who somebody has implemented this interface too outside the SDK.

Does this change introduce a breaking change?

Best Answer

If you only change the interface as outlined here, then yes you are breaking the code. Because every implementation of the interface must now return a String, and before the change none of them does.

Assuming you make each implementor actually return a String, then no, this cannot break the code because no caller of any of these methods is using the return value.

One obscure exception: if you are using reflection, this could break things. Because your reflection code may still be looking for the null-returning methods.

Related Topic