import java.util.HashMap;
public class Test {
主要方法如下:
public <T extends Number> Double pringArray(T[] t) {// double类型最大,输入其他类型可在main方法中转换
double sum = 0;
for (T t1 : t) {//把输入在数组中的数相加
sum += t1.doubleValue();
}
return sum;//返回最后结果
}
主方法:
public static void main(String[] args) {
Test<Integer> test = new Test<Integer>();
Byte[] aBytes = { 1, 2, 3 };
double s = test.pringArray(aBytes);
System.out.println((byte) s);//转换类型
Integer[] aIntegers = { 1, 2, 3, 4 };
s = test.pringArray(aIntegers);
System.out.println((int) s);//转换类型
Float[] aFloats = { 1.5f, 2.5f };
s = test.pringArray(aFloats);
System.out.println((float) s);//转换类型
Double[] aDoubles = { 1.4d, 3.6d, 4d };
s = test.pringArray(aDoubles);
System.out.println((double) s);//转换类型
String[] aStrings = {"a","b","c"};
Integer[] a = new Integer[aStrings.length];
for (int i = 0; i < aStrings.length; i++) {
System.out.print("字符"+aStrings[i]+"转换成哈希值为:");
a[i] = (aStrings[i]).hashCode();
System.out.println(a[i].hashCode());
}
s = test.pringArray(a);
System.out.println("哈希值相加后为:"+(int)s);//转换类型
}}