I always thought CharSequence[] and String[] were essential the same, however :
I have some code that has the following :
CharSequence[] mEntries;
...
String[] mEntriesString = (String[]) mEntries;
ListAdapter adapter = new ArrayAdapter<String>(getContext(), R.layout.two_lines_list_preference_row, mEntriesString)
When the code runs I get
java.lang.ClassCastException: java.lang.CharSequence[] cannot be cast to java.lang.String[]
So two questions ?
- why can this cast not happen
- why does the ArrayAdapter not allow for a CharSequence[] in it’s constructor.
CharSequenceis interface whichString,StringBuffer,StringBuilderclasses implements. SoCharSequencecan hold any of this implementation class’s Object AndCharSequence#toStringreturnsString, try –