If I change a class from `public final class MyCla...
# library-development
m
If I change a class from
public final class MyClass(something: Any)
to
public open class MyClass(something: Any)
, will that break backward compatibility?
🚫 1
a
Are you asking about api or binary compatibility? I don't know the answer... I just know to ask the question.
m
Both? I thought there would be a problem for Java if something compiled against the previous version where it was
final class
, and then Project A updates that dependency where it's now
open class
, but not sure.
And my concern is not only with Java/Android, but with other Multiplatform targets as well.
d
It can theoretically break existing behavior. Since it was final, users could safely check if an object class equals that class in place of using "is" (instanceof) whereas only "is" would produce correct results now.
m
Oh good one. Forutunately,
equals
and
hashCode
of the actual classes I'm looking at doing this to are already overridden and implemented in a way such that there would be no change in behavior there.
d
I think that implies that your equals implementation doesn't abide by the equals contract as it breaks symmetry. A == B if and only if B == A. If B is a subclass instance then it sounds like A == B will be true in your implementation but B == A will be false.
Also, note that my previous comment was referring to calling equals on the class, not on the object (
obj.class == expectedClass
) so the behavior would change regardless of the implementation of your equals override.
m
> I think that implies that your equals implementation doesn't abide by the equals contract as it breaks symmetry. A == B if and only if B == A. If B is a subclass instance then it sounds like A == B will be true in your implementation but B == A will be false. Nope. It's comparable to how
equals
is implemented for lists. The implementation itself is stateless with an immutable configuration. Only the
name(): String = "UTF-8"
and components of the immutable configuration are compared for equality. So A == B && B == A if both have the same configurations and return the same
name()
> Also, note that my previous comment was referring to calling equals on the class, not on the object Very good point; I did not consider that...