I'm wrote a simple method with generic to add Integers, floats and double but got getting an syntx error when adding two objects. Not sure how to achieve this with generics.
package pack;
public class Main7 {
public static <E> void addData(E objA, E objB)
{
System.out.println(objA+objB); //getting error that + operator not allowed
}
public static void main(String[] args) {
Integer objA = new Integer(10);
Integer objB = new Integer(20);
Float objF = new Float(10.01);
Float objG = new Float(11.01);
addData(objA, objB);
addData(objF, objG);
}
}