1

I wrote some code using javax.measure, and when I pulled updated code from our repository, I am getting a Bound Mismatch error whenever I try to use <Length> from javax.measure.

Edit The Exact Error Is:

Bound mismatch: The type Length is not a valid substitute for the bounded parameter <Q extends Quantity> of the type BaseUnit<Q>

I moved the code to a clean workspace and everything was just fine, but for some reason in my main workspace it isn't working.

Any ideas to why this is the case? I'm using eclipse and the code in question is below

import javax.measure.Measure;
import javax.measure.quantity.Length;
import javax.measure.unit.BaseUnit;

public class MyUnit{
    BaseUnit<Length> unitType;
    Measure<Length> unitValue;

    public MyUnit(double value, String abbreviation) {
        this.unitType = new BaseUnit<Length>(abbreviation);
        this.unitValue = Measure.valueOf(value, unitType);
    }

    public double getValue() {
        return (double)this.unitValue.getValue();
    }

    public String getUnit() {
        return this.unitType.getSymbol();
    }
}
Mr Lister
  • 45,515
  • 15
  • 108
  • 150
pianoisland
  • 163
  • 1
  • 1
  • 10

1 Answers1

1

Measure<V,Q extends Quantity> requires two type parameters:

  • V the type of the result returned by getValue().

  • Q the Quantity of the Unit returned by getUnit().

As the MyUnit constructor specifies double, the declaration should be, for example,

Measure<Double, Length> unitValue;
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • Thanks for the response. I just pulled the whole entire project down from the repository to a clean directory and it fixed the problem, I still have no clue what was causing it. – pianoisland Jan 12 '16 at 21:44
  • Sound like a version control problem; glad you got it working. – trashgod Jan 13 '16 at 01:47