Okay, the method you're trying to implement is impossible. Well, at least for me. I don't know how to solve it. But anyways, I'll try to explain why you're getting the error:
The operator + is undefined for the argument type(s) T, T
This simply means, What does a + do with a type T?
Well, it makes sense when we try to do something like:
Calculadora<Integer> c = new Calculadora<Integer>();
Because Integer can be cast to int and the compiler knows exactly how to add int with int right?
But since T can be of any type, what if we do something like:
Calculadora<Cat> c = new Calculadora<Cat>();
Clearly, we don't know how the hell you will add a Cat with another Cat. That's why the compiler is giving you that error, it's telling you, I don't know how to add this Type together. I can only add numbers and Strings.
Hope this'll help. :)
EDIT 2:
Well, the way I see it, if you really need to do something like that, you're going to have to change your class and method declaration a bit, something like:
//Limit only the Generics to subtypes of Number
class Calculadora<T extends Number> {
//Return a specific type (Can be Double, Float, Long, etc.)
Integer suma(T a, T b) {
//Change this based on your return type (Can be double, float, long, etc.)
int sum = 0;
if (a instanceof Number && b instanceof Number) {
//Change this accordingly too (Can be doubleValue(), floatValue(), longValue(), etc.)
sum = a.intValue() + b.intValue();
}
return sum;
}
}
This is only for Integer. You can change this to any subtype of Number if you want.