gpt4 book ai didi

java - 实现相同接口(interface)的接口(interface)内的内部类,我们通过这个实现什么?

转载 作者:IT老高 更新时间:2023-10-28 20:35:43 25 4
gpt4 key购买 nike

我的问题:

我正在查看 TextWatcher 的源代码,但我没有在这里得到这个概念。扩展到 NoCopySpan 有什么意义?

TextWatcher.java:

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);
}

NoCopySpan.java:

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 只是一个 marker interface .根据 javadoc,它用于修改 Spanned 对象的复制例程的行为(它依赖于组件的类型)。例如 android.text.SpannableStringBuilder使用此类继承信息在构建时跳过跨度复制。

这种方法有一些缺点,但仍然很常见。 Concrete 类存在的原因是为了提供方便的方式来构造 NoCopySpan 接口(interface)的on-op dummy(或默认)实现。

关于java - 实现相同接口(interface)的接口(interface)内的内部类,我们通过这个实现什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38717769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com