# Vector<F extends Field>#times(Vector F) has wrong return type F

## Details

• Type: Bug
• Status: Resolved
• Priority: Major
• Resolution: Fixed
• Affects Version/s: current
• Fix Version/s:
• Component/s:
• Labels:
None
• Environment:

Operating System: All
Platform: All

• Issuezilla Id:
29

## Description

The Vector implementation declares the result of a scalar multiplication with
two vectors of type F to be of type F too. This is not correct.

Sample code
-----------

package test;

import javax.quantities.Length;

import org.jscience.mathematics.vectors.Vector;
import org.jscience.physics.measures.Measure;

public class VectorTest {

/**

• @param args
*/
public static void main(String[] args) { Measure<Length> ax = Measure.valueOf(1, Length.SI_UNIT); Measure<Length> ay = Measure.valueOf(2, Length.SI_UNIT); Measure<Length> az = Measure.valueOf(3, Length.SI_UNIT); Measure<Length> bx = Measure.valueOf(5, Length.SI_UNIT); Measure<Length> by = Measure.valueOf(7, Length.SI_UNIT); Measure<Length> bz = Measure.valueOf(9, Length.SI_UNIT); Vector<Measure<Length>> a = Vector.valueOf(ax, ay, az); Vector<Measure<Length>> b = Vector.valueOf(bx, by, bz); Measure<Length> ab = a.times(b); // should be Measure<Area> !!! System.out.println("a = " + a); System.out.println("b = " + b); System.out.println("ab = " + ab); }

}

Sample result
-------------

a =

{1 m, 2 m, 3 m}

b =

{5 m, 7 m, 9 m}

ab = 46 mÂ²

Suggestion
----------

Change the return type of the method from F to Field. Caller has to cast the result.

## Activity

Hide

The issue is fixed by a more rigourous class parameterization in version 3.1.0
When implementing a mathematical structure the preferred notation is now:
<F extends Field<F>> or <R extends Ring<R>> ...
But this come with a price: The field for measurements is now Measure<?>
In other words, you can create a Vector<Measure<?>> but not
Vector<Measure<Length>> (which makes senses as Measure<?> times Measure<?> is of
type Measure<?> but Measure<Length> times Measure<Length> is not of type
Measure<Length> but Measure<Area> as previously mentioned.

Show
dautelle added a comment - The issue is fixed by a more rigourous class parameterization in version 3.1.0 When implementing a mathematical structure the preferred notation is now: <F extends Field<F>> or <R extends Ring<R>> ... But this come with a price: The field for measurements is now Measure<?> In other words, you can create a Vector<Measure<?>> but not Vector<Measure<Length>> (which makes senses as Measure<?> times Measure<?> is of type Measure<?> but Measure<Length> times Measure<Length> is not of type Measure<Length> but Measure<Area> as previously mentioned.
Hide

Show

## People

• Assignee:
jscience-issues
Reporter:
vieta