Can we represent “self class” in Java (or Kotlin)?

I think the question title is a little bit confusing, but I can't find a mo…
关注者
44
被浏览
5,275
登录后你可以
不限量看优质回答私信答主深度交流精彩内容一键收藏

工程上的作法基本上就是加个泛型参数了吧,比如说Java的Comparator:

public interface Comparable<T> { int compareTo(T o); }
public final class String implements Comparable<String> /* and something else */ { /* xxx */ }

但是感觉约束力还是不太够,不过很多都这么做的就是了。