Editable is an interface, the code as follows is a method of EditText class, which shows in the android source code:
public Editable getText() {
return (Editable) super.getText();
}
i want to make it clear that how to understand the code (Editable)super.getText(), i have two ways to understand the line of code:
1.cast super class of EditText(the super class of EditText is TextView) to Editable , then invoke the getText() method with Editable,
2.invoke the getText() method with the super class(TextView), then cast the return class to Editable
which one is right? According to the operator precedence, the operator () . both have the highest precedence, and the associativity is left, so thought may be the first way is right. But it made me more confused. you know, the super class of EditText is TextView, and i made a cast from TextView to Editable? TextView has nothing to do with Editable, how can it cast successfully?
The return type of
TextView.getText()isCharSequenceandEditableis a sub-class ofCharSequence.Therefore…
…is simply casting a
CharSequence(returned by the call tosuper.getText()) to anEditable.