我明白為什么我無法向第二個方法傳遞引數InterestPoint<M>,因為它是靜態的,但是為什么當我試圖將它宣告為回傳型別時,會出現錯誤?洗掉型別引數可以解決這個問題,但是我又被留下了警告。非法使用引數化的類'InterestPoint'.
public record InterestPoint<M> (Coordinate coordinate, M marker) {
public final InterestPoint<M> validate() {
return this;
}
public static final InterestPoint<M> validate( InterestPoint interestPoint) {
interestPoint.validate()。
return interestPoint;
}
uj5u.com熱心網友回復:
M通用型別引數屬于一個實體,而靜態方法不屬于一個特定的實體,而是屬于一個類。讓靜態方法回傳通用型別的方法是直接給它添加一個型別引數。例如:
public static final < N> InterestPoint<N> validate(InterestPoint<N> interestPoint) {
interestPoint.validate()。
return interestPoint;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/318603.html
標籤:
