Hi I want to create a java object which can be defined for multiple Dimensions and let the user choose the one he desires. As so I have created a new class which extends the BaseAmount class so the user can define an element of MassAmount or another of Temperature and then it can retrieve the values in an homogenised way.
My problem comes at compilation time, because the compiler is not raising any problem if for a MassAmount I use AMPERE units. Can someone shed a light on this? I am guessing I am doing something wrong
I put my code
import org.unitsofmeasurement.quantity.Quantity;
import org.eclipse.uomo.units.impl.BaseAmount;
import org.unitsofmeasurement.unit.Unit;
@SuppressWarnings("rawtypes")
public class MeasurableElement<T extends BaseAmount> {
T value;
public MeasurableElement( T typeAmount){
value = (T) typeAmount;
}
@SuppressWarnings("unchecked")
public <U extends Unit> void forceValue(double newVal, U unit ) {
value = (T) BaseAmount.valueOf(newVal, unit);
}
}
and my testing code
MeasurableElement<MassAmount> me = new MeasurableElement(new MassAmount(1000, org.eclipse.uomo.units.SI.KILOGRAM));
me.forceValue(5.2, org.eclipse.uomo.units.SI.AMPERE);
Thanks in advance