For the API (Android SDK API version 8) functions whose definitions list character sequence parameters, I can feed the function String instead. Best part is that they work the same way, no hassle, no warnings.
Is there a difference between the two types? And more importantly, is there an inherent danger if I send the function a String instead of a character sequence???
Thanks for any clarifications!!! 😀
Yes.
Stringis a class, andCharSequenceis an interface. If a method accepts aCharSequence, it only requires the argument to implement the methods in the interface, which gives a greater flexibility, than if it would accept only aString.The following API classes implement
CharSequence:CharBuffer,Segment,String,StringBuffer,StringBuilder. That is, aStringis aCharSequence, and can thus be passed to a method that accepts aCharSequence.No, there is no danger.
Stringproperly implementsCharSequence, and that’s all the method will require to function properly.