我正在查看Android示例,并在代码中找到了一个我不明白的地方。这是代码(取自here) :
public class RosterFragment extends BrowseFragment
implements OnItemViewClickedListener {
// code
@Override
public void onItemClicked(Presenter.ViewHolder viewHolder,
Object o,
RowPresenter.ViewHolder rowViewHolder,
Row row) {
((LeanbackActivity)getActivity()).showPreso((PresoContents)o);
}
// code
}
我用jd-gui反编译OnItemViewClickedListener
类,声明如下
package android.support.v17.leanback.widget;
public abstract interface BaseOnItemViewClickedListener<T>
{
public abstract void onItemClicked(Presenter.ViewHolder paramViewHolder, Object paramObject, RowPresenter.ViewHolder paramViewHolder1, T paramT);
}
Javadoc对类定义说了同样的话。
注意最后一个参数,它在声明接口时有T
类型,因此我应该根据jls的类型Object
来理解它。但是代码编译成功,结果是允许覆盖Row
Object
的{{1}}参数。我试着自己编写相同的结构并获得这两个类:
interface A<T>{
public void dodo(Integer a, Object b, Float c, T t);
}
class B implements A{
@Override
public void dodo(Integer a, Object b, Float c, String t) {
}
}
尝试编译会导致多个错误:B is not abstract and does not override abstract method dodo(Integer,Object,Float,Object) in A
和method does not override or implement a method from a supertype
问题是:是什么让RosterFragment
代码可编辑?