Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does changing the return type of a function for a child type breaks binary compatibility?

Let's go straight to it :

Old code :

public interface IFoo {}
public class Foo : IFoo {}
...
public static IFoo Bar() { return new Foo(); }

New code :

public static Foo Bar() { return new Foo(); }

Obviously there should be no problem here, everything you were doing on the old return type, you can still do on the new return type, any is, as or cast should behave the same as before...

So did I break binary compatibility, or can I just release it as a minor version without bothering users ?

like image 874
Zonko Avatar asked Nov 21 '25 19:11

Zonko


1 Answers

This breaks binary compatibility, but not (most) compile-time compatibility issues, so it's typically an easy migration.

Note that it can even be a compile-time break if the client code constructs a delegate from the method.

like image 144
Reed Copsey Avatar answered Nov 23 '25 08:11

Reed Copsey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!