java中<T> T和T的区别?

如果你希望 getMax 方法的返回值类型为 T,就要这样去定义getMax方法:

public T getMax()

如果你希望 getMax 方法返回值的类型由调用者决定,那么就这么去定义 getMax 方法:

public <A> A getMax() {
    //...
    return (A)result;
}

 

https://www.cnblogs.com/jpfss/p/9929152.html

 

posted @ 2020-12-04 09:38  天妖姥爷  阅读(220)  评论(0编辑  收藏  举报