I came across this when helping a noobie understand why this doesn’t compile:
someString.replace('A',"BB")
It got me thinking; why doesn’t the Character class implement CharSequence.
Logically a Character is a sequence of 1, thus there’s no reason it shouldn’t implement it.
Doing so would have interesting consequence when mixed with autoboxing.
Thanks to autoboxing, the uncompilable code above would start compiling. (char autoboxes to Character, which would implement CharSequence & thus meet the contract of replace(CharSequence,CharSequence))
I’m obviously not advocating such a change, as it’d introduce all sorts of potential confusion as to precisely what method was being invoked, and possible performance problems in the event of typos.
Still, it was something I hadn’t noticed or considered before.