java.lang.String is declared as final, however are there any mechanisms available legitimate or otherwise to extend it and replace the equals(String other) method?
2) Strings are immutable and final in Java Since String is final there is no way anyone can extend String or override any of String functionality. Now if you are puzzled why String is immutable or final in Java.
The java.lang.String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class.Strings are constant, their values cannot be changed after they are created.
String is immutable (More details of this concept are in the document). It does not allow the existence of subclass.
No, absolutely not. If you want some "other" kind of string, create another type which might contain a string:
public final class OtherString { private final String underlyingString; public OtherString(String underlyingString) { this.underlyingString = underlyingString; } // Override equals however you want here }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With