Is there a way to refer to the current type with a type variable?

后端 未结 7 1681
悲&欢浪女
悲&欢浪女 2020-11-22 03:01

Suppose I\'m trying to write a function to return an instance of the current type. Is there a way to make T refer to the exact subtype (so T should

7条回答
  •  孤独总比滥情好
    2020-11-22 03:48

    If you want something akin to Scala's

    trait T {
      def foo() : this.type
    }
    

    then no, this is not possible in Java. You should also note that there is not much you can return from a similarly typed function in Scala, apart from this.

提交回复
热议问题