I was looking at the source code of TextWatcher and I didn't get the concept here. What was the point of extending to NoCopySpan?
public interface TextWatcher extends NoCopySpan { public void beforeTextChanged(CharSequence s, int start, int count, int after); public void onTextChanged(CharSequence s, int start, int before, int count); public void afterTextChanged(Editable s); }
package android.text; /** * This interface should be added to a span object that should not be copied into a new Spanned when performing a slice or copy operation on the original Spanned it was placed in. */ public interface NoCopySpan { /** * Convenience equivalent for when you would just want a new Object() for * a span but want it to be no-copy. Use this instead. */ public class Concrete implements NoCopySpan {} }
A normal class can implement any number of interfaces but the anonymous inner class can implement only one interface at a time. A regular class can extend a class and implement any number of interfaces simultaneously. But anonymous Inner class can extend a class or can implement an interface but not both at a time.
Yes, you can define an interface inside a class and it is known as a nested interface. You can't access a nested interface directly; you need to access (implement) the nested interface using the inner class or by using the name of the class holding this nested interface.
Advantages. The main advantages of a nested (inner) class are: It shows a special type of relationship, in other words, it has the ability to access all the data members (data members and methods) of the main class including private. They provide easier code because it logically groups classes in only one place.
NoCopySpan
is just a marker interface. According to javadoc it is used to modify behavior of copy routine of Spanned
objects (it relies on type of components). For example android.text.SpannableStringBuilder
uses such inheritance information to skip spans copying upon construction.
This approach has some drawbacks but still pretty common. The reason of Concrete
class existence is to provide convenient way to construct on-op dummy (or default) realization of NoCopySpan
interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With