问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
import java.util.Scanner;
public class oj2078 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int id = 1;
String str = sc.next();
switch (str){
case "I":
GnnericsA<Integer> gg1 = new GnnericsA<>();
int num1 = sc.nextInt();
int num2 = sc.nextInt();
gg1.setT(num1);
System.out.println("Case " + id++ + ":整数类,和为" + gg1.sum(num2));
break;
case "S":
GnnericsA<String> gg2 = new GnnericsA<>();
String str1 = sc.next();
String str2 = sc.next();
gg2.setT(str1);
System.out.println("Case " + id++ + ":字符串类,和为" + gg2.sum(str2));
}
}
}
}
class GnnericsA<T>{
private T t;
T tt;
public void setT(T t){
this.t = t;
}
public T sum(T t1) {
return this.t + t1 ;
}
}
运行结果及报错内容
Operator '+' cannot be applied to 'T', 'T'
我想要达到的结果
希望不违背题目要求