Question: This is probably a very simple problem, but I was wondering how to find all floats in a file and surround them by some text, e.g.

Input file:

```
input1 & X & Y & Z \\
input2 & ...

```

Output file:

```
input1 & float(X) & float(Y) & float(Z) \\
input2 & ...

```

I was thinking about using sed or awk, but I don't see how the found float can be reused in the replaced string.

Answer: 
The compiler doesn't know that you *can* multiply and add `T` values - it's not the `return` part which the problem, it's the expression itself. You'll see the same effect if you split the two parts:

```
T result = a + b;
return result;

```

It will be the first line that fails - and there's no particularly clean answer to this. Generics just aren't built for this sort of work in Java. What you *could* do is have:

```
public abstract class GenericMath<T extends Number> {
    public abstract T add(T a, T b);
    public abstract T multiply(T a, T b);
    // etc
}

public final class IntegerMath extends GenericMath<Integer> {
    public Integer add(Integer a, Integer b) {
        return a + b;
    }

    // etc
}

```

... and similar classes for `DoubleMath` etc.

Then:

```
// Alternatively, have a static factory method in GenericMath...
GenericMath<Integer> math = new IntegerMath();
int x = math.add(5, 2);

```
You need to do these things:

1. Bound the generic type to Number
2. Make the `add()` etc method `abstract` and return `T`
3. Provide implementations for each type you want to support

Like this:

```
public abstract class GenericMath<T extends Number> {
    public T a,b;

    public abstract T add();
    public abstract T multiply();
}

public class IntegerGenericMath extends GenericMath<Integer> {
    public Integer add() {
        return a + b;
    }
    public Integer multiply() {
        return a * b;
    }
}

// similar for Double

public static void main(String[] args) {

    IntegerGenericMath x=new IntegerGenericMath();
    x.a=5;
    x.b=10;
    int z=x.add();

    DoubleGenericMath y = new DoubleGenericMath();
    y.a = 5.5;
    y.b = 10.2;
    double g=y.multiply();
}

```

There's a lot of auto boxing going on here, which won't work genericly, which is why you need separate classes for each type.