How can I make an interface instance method accept arguments of the same class only, really?

前端 未结 5 973
长情又很酷
长情又很酷 2020-12-11 07:39

This SO discussion proposes the following idiom:

public interface IComparable> {
    int compare(T t);
}
5条回答
  •  误落风尘
    2020-12-11 07:45

    Indeed. I'd advocate that we use This as the conventional name for such type parameters

    public interface IComparesWith 
    {
        int compare(This t);
    }
    

    my previous answer: Convenient way to write generic interface that points out to its implementor

提交回复
热议问题