@SuppressWarnings("unchecked")
  public static <T> T add(T op1, T op2) {
    if (op1.getClass() != op2.getClass()) {
      throw new RuntimeException("Arguments of different classes: " + op1 + " " + op2);
    }

    if (Byte.class.isInstance(op1)) {
      return (T)(Byte)(byte)(((Byte) op1).byteValue() + ((Byte) op2).byteValue());
    }
    if (Short.class.isInstance(op1)) {
      return (T)(Short)(short)(((Short) op1).shortValue() + ((Short) op2).shortValue());
    }
    if (Character.class.isInstance(op1)) {
      return (T)(Character)(char)(((Character) op1).charValue() + ((Character) op2).charValue());
    }
    if (Integer.class.isInstance(op1)) {
      return (T)(Integer)(((Integer) op1).intValue() + ((Integer) op2).intValue());
    }
    if (Float.class.isInstance(op1)) {
      return (T)(Float)(((Float) op1).floatValue() + ((Float) op2).floatValue());
    }
    if (Long.class.isInstance(op1)) {
      return (T)(Long)(((Long) op1).longValue() + ((Long) op2).longValue());
    }
    if (Double.class.isInstance(op1)) {
      return (T)(Double)(((Double) op1).doubleValue() + ((Double) op2).doubleValue());
    }

    throw new UnsupportedOperationException("Invalid for arbitrary types: " + op1 + " " + op2);
  }
@ SuppressWarnings ( "unchecked" ) public static < T > T add ( T op1 , T op2 ) { if ( op1 . getClass ( ) != op2 . getClass ( ) ) { throw new RuntimeException ( "Arguments of different classes: " + op1 + " " + op2 ) ; } if ( Byte . class . isInstance ( op1 ) ) { return ( T ) ( Byte ) ( byte ) ( ( ( Byte ) op1 ) . byteValue ( ) + ( ( Byte ) op2 ) . byteValue ( ) ) ; } if ( Short . class . isInstance ( op1 ) ) { return ( T ) ( Short ) ( short ) ( ( ( Short ) op1 ) . shortValue ( ) + ( ( Short ) op2 ) . shortValue ( ) ) ; } if ( Character . class . isInstance ( op1 ) ) { return ( T ) ( Character ) ( char ) ( ( ( Character ) op1 ) . charValue ( ) + ( ( Character ) op2 ) . charValue ( ) ) ; } if ( Integer . class . isInstance ( op1 ) ) { return ( T ) ( Integer ) ( ( ( Integer ) op1 ) . intValue ( ) + ( ( Integer ) op2 ) . intValue ( ) ) ; } if ( Float . class . isInstance ( op1 ) ) { return ( T ) ( Float ) ( ( ( Float ) op1 ) . floatValue ( ) + ( ( Float ) op2 ) . floatValue ( ) ) ; } if ( Long . class . isInstance ( op1 ) ) { return ( T ) ( Long ) ( ( ( Long ) op1 ) . longValue ( ) + ( ( Long ) op2 ) . longValue ( ) ) ; } if ( Double . class . isInstance ( op1 ) ) { return ( T ) ( Double ) ( ( ( Double ) op1 ) . doubleValue ( ) + ( ( Double ) op2 ) . doubleValue ( ) ) ; } throw new UnsupportedOperationException ( "Invalid for arbitrary types: " + op1 + " " + op2 ) ; }
An intrinsic that is replaced with plain addition of arguments for
primitive template types. Invalid for non-number generic types.