[ 
https://issues.apache.org/jira/browse/MATH-284?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12794696#action_12794696
 ] 

Luc Maisonobe commented on MATH-284:
------------------------------------

Using a new interface would not help solving this issue as the linear algebra 
classes that use field elements are declared with respect to FieldElement wich 
in turns refer to Field and not some new ImprovedField interface.

Klaus, could you tell more about your use case so we can find another way to 
solve this ?
If I understand correctly, you have a hierarchy similar to:
{code}
public class Base implements FieldElement<Base> {

    public static final Base ZERO = new Base(...);

    public static final Base ONE    = new Base(...);

    BaseField getField() {
        return BaseField.getInstance();
    }

}

public class BaseField implements Field<Base> {

    public Base getZero() {
        return Base.ZERO;
    }

    public Base getOne() {
        return Base.ONE;
    }

}

public class Derived extends Base {
    ...
}
{code}

If this is the case could you tell us if your matrices can contain both Base 
and Derived elements. If so, then Derived should still rely on the base 
implementation of getField(), which would lead to Base[] arrays being 
allocated, as such arrays may contain Derived elements. If not, then Derived 
should implement its own getField() method and a DerivedField class should be 
created as well as Derived.ZERO and Derived.ONE to get a more specialized class.




> Avoid ArrayStoreException
> -------------------------
>
>                 Key: MATH-284
>                 URL: https://issues.apache.org/jira/browse/MATH-284
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>            Reporter: Klaus Hartlage
>            Priority: Minor
>         Attachments: math-284.patch
>
>
> Add a new method
> org.apache.commons.math,Field#getRuntimeClass():
> ...
>     /**
>      * Returns the runtime class of the FieldElement. 
>      * 
>      * @return The {...@code Class} object that represents the runtime
>      *         class of this object.
>      */
>     Class<? extends FieldElement> getRuntimeClass();
> ...
> and replace all occurrences of 
>   Array.newInstance(field.getZero().getClass(),....)
> with
>   Array.newInstance(field.getRuntimeClass(),....)
> to avoid the throwing of ArrayStoreException in the case you have a type 
> hierachy of Fields with a common interface
> and the array should have the interface type at runtime.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to