Skip to main content

Re: Remove "generic" multiply/divide operations from Quantity

  • From: Martin Desruisseaux < >
  • To:
  • Subject: Re: Remove "generic" multiply/divide operations from Quantity
  • Date: Sat, 18 Oct 2014 17:13:05 +0900
  • Organization: Geomatys

Le 17/10/14 11:28, Otávio Gonçalves de Santana a écrit :
> On Thu, Oct 16, 2014 at 10:03 PM, Martin Desruisseaux
> <
> <mailto: >>
>  wrote:
>
>     This method signature is wrong - the reality is not an absence of
>     relationship. The reality is a relationship that we can not
>     express in Java.
>
> That is the point, there is two different things the semantic
> (business rule) and the Java core source.
>
The Java source code is supposed to represent the business semantic to
the greatest extend allowed by the language. The UNITSOFMEASUREMENT-62
signatures are totally artificial with no connection with the business
semantic. This is the reason why they are unsafe.


>     And about the relationship is:
>
>     the operations in Quantity results in another quantity.
>
This is expressed by Quantity<?>, not but Quantity<R>. The later means
"/the operation in Quantity result in another quantity whose type is the
type of the local variable in caller's code/", which is not the real
semantic of those operations. This is why this semantic is impossible to
implement without unprovable "unsafe cast" warnings on the library side.


>     Speed = Length.multiply(Time);
>
Just for making sure that there is no confusion on what I'm proposing, I
will rewrite at (please note the cast):

    Speed speed = (Speed) length.divide(time);


>     But I can do same think wrong like this without the implementation
>     take care:
>
>            Mass = Length.multiply(Time);
>
Right, someone could write:

    Mass mass = (Mass) length.divide(time);

(Note the cast). The big difference between the (Mass) and
(Quantity<Mass>) casts is that the first one is safe at runtime (it will
thrown a ClassCastException) while the second cast will give an illusion
of success: it will pass silently, but the wrong type is likely to cause
some unpredictable failure later.

The fact that the (Mass) cast is safe at runtime is the reason why the
compiler emits no warning for this cast, while it emit a warning for
(Quantity<Mass>) cast.


>     But it's the first question that I did, take care or not this
>     operations what it the goals of this JSR.
>
You can not take care of this operation safely in the Java language.
Forget about that, it is *impossible* with the current parameterized
type syntax (it would be possible if a future Java version supported
arithmetic operations on parameterized type like what C/C++ templates
allow), and JEP-101 has nothing to do with this limitation. If you do
not believe me, see my proposal to Werner to restart the logical
demonstration step-by-step. The only safe operations are casting to the
specific interface like (Speed), or providing a Class<R extends
Quantity<R>> argument somewhere (either in operation methods or in a
asType method).

    Martin



Re: Remove "generic" multiply/divide operations from Quantity

(continued)

Re: Remove "generic" multiply/divide operations from Quantity

Leonardo Lima 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/18/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/18/2014

Re: Remove "generic" multiply/divide operations from Quantity

Otávio Gonçalves de Santana 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Otávio Gonçalves de Santana 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Werner Keil 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Werner Keil 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/18/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/18/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/18/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/18/2014

Re: Remove "generic" multiply/divide operations from Quantity

Werner Keil 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/18/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Werner Keil 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/18/2014

Re: Remove "generic" multiply/divide operations from Quantity

Jean-Marie Dautelle 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Werner Keil 10/17/2014

Re: Remove "generic" multiply/divide operations from Quantity

Martin Desruisseaux 10/18/2014

Re: Remove "generic" multiply/divide operations from Quantity

Werner Keil 10/18/2014
 
 
Close
loading
Please Confirm
Close