Java generic type

后端 未结 4 1356
野的像风
野的像风 2020-12-09 12:07

When I have an interface

public interface Foo {
    T someMethod();
}

is there any way to assure that when some class implements t

4条回答
  •  青春惊慌失措
    2020-12-09 13:01

    This cannot be done because of Type Erasure.

    EDIT :

    I got down voted, here is more explanation :

    public interface Foo;
    

    T from above is available in run time, so it cannot be checked. However, one could custom annotation that could enforce this.

提交回复
热议问题