java的泛型方法

public class Da {
    public static <A,T>T add(A a, T b)  {

        return b;
    }

    public static void main(String[] args) {
        String a = "aaa";
        Integer b = 9;
        System.out.println(add(a,b));
    }
}
  1. 方法的泛型在返回值处定义,多个的话就用逗号分开。
  2. 也可以在类上定义。
发布了202 篇原创文章 · 获赞 6 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/fall_hat/article/details/104064169