Why there is function: CharSequence#substring?


#1

I spent a whole day to detect a strange hidden bug in Android app.

Caused by use CharSequence#substring instead of String#substring by accident. Thanks god I finally finished this pain.

I think this function named substring is confusing: it calls subSequence then toString.


#2

Why do you think substring defined this way is confusing? What was your bug with it?


#3

The bug is about custom span, .
because SpannableString implements CharSequence, but sp.substring() is different to sp.toString().substring().
Or in other words,
sp.subSequence().toString() is confusing with sp.toString().substring().


#4

In what situations these two expressions can produce different result?


#5

Because the implements of subSequence is not about String.
SpannableString may cause different effect sometimes, it’s strange. Always post measures to UI thread but nothing happens on screen.