Hisham Muneer Hisham Muneer - 2 months ago 10x
Android Question

Inner Class inside an Interface implementing same Interface, what we are achieving by this?

My Question:

I was looking at the source code of TextWatcher and I din't get the concept here.
What was the point of extending to NoCopySpan? Can anyone please throw some light.


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 {


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.