更多参考见
如果对generic的翻译不太准确请见谅!
public class apa{public static void main(String[] args){A ai = new A();String x[] = {"1", "3", "5", "6"};int ct = 0;ct = ai.<String>count(x);System.out.println(ct);}}class A{public <T> int count(T[] a){int c = 0;for(T b : a){c++;}return c;}}在A类里定义了一个泛化的方法函数count,返回值为int,形参为泛型T型的数组a。
请注意泛型函数的调用方式
ai.<String>count(x);
实在方法函数前用<和>括起来某具体类型。
,人生才会更有意义。如果没有梦想,那就托做庸人。