Use Advanced Search to search the entire archive.
Re: Remove "generic" multiply/divide operations from Quantity
- From: Otávio Gonçalves de Santana <
>
- To:
- Subject: Re: Remove "generic" multiply/divide operations from Quantity
- Date: Thu, 16 Oct 2014 23:51:49 -0300
And considering the old method, what do avoid me to to something like
that?:
Quantity<Time> time = ...;
Quantity<Length> length = ...;
Quantity<Mass> result = (Quantity<Mass>) time.multiply(length);
On Thu, Oct 16, 2014 at 11:28 PM, Otávio Gonçalves de Santana <
>
wrote:
>
>
>
On Thu, Oct 16, 2014 at 10:03 PM, Martin Desruisseaux <
>
>
>
wrote:
>
>
> Otavio, all the JDK examples you gave below are *safe*, because:
>
>
>
> - In an empty list/set/map, the type of elements (Integer, String,
>
> etc.) become irrelevant.
>
> - In asList, the relationship between input and output types is
>
> correctly expressed. The method signature:
>
>
>
> <T> List<T> asList(T... a)
>
>
>
> said: "*the type of elements in the list is the same than the type of
>
> the given elements*", which is correct.
>
>
>
> By contract, UNITSOFMEASUREMENT-62 is *unsafe*. The following method
>
> signature:
>
>
>
> <T extends Quantity<T>,R extends Quantity<R>> Quantity<R>
>
> multiply(Quantity<T> that)
>
>
>
> said: "*there is no relationship between the type of this instance Q,
>
> the input type T and the output type R*" (otherwise, please show me
>
> where the relationship is expressed). The fact that this signature declares
>
> no relationship is why the compiler accepts anything like "mass =
>
> length.multiply(time)". This method signature is wrong - t*he 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.
>
>
>
> And about the relationship is:
>
>
>
> the operations in Quantity results in another quantity.
>
>
>
> So:
>
>
>
>
>
> Speed = Length.multiply(Time);
>
>
>
>
>
> - public interface Speed extends Quantity<Speed>
>
> - public interface Time extends Quantity<Time>
>
> - public interface Speed extends Quantity<Speed>
>
>
>
>
>
> But I can do same think wrong like this without the implementation take
>
> care:
>
>
>
>
>
> Mass = Length.multiply(Time);
>
>
>
>
>
> - Length: Quantity
>
> - Time: Quantity
>
> - Speed: Quantity
>
>
>
>
>
> But it's the first question that I did, take care or not this operations
>
> what it the goals of this JSR.
>
>
>
>
>
> Martin
>
>
>
>
>
>
>
> Le 17/10/14 08:44, Otávio Gonçalves de Santana a écrit :
>
>
>
> About the question of Martin, Yes we can do and there are in in SE api
>
> such java.util.Collections
>
> <http://docs.oracle.com/javase/7/docs/api/java/util/Collections.html>,
>
> java.util.Arrays
>
> <http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html>, etc.
>
>
>
> List<Integer> intergers = Collections.emptyList();
>
> List<String> strings = Collections.emptyList();
>
>
>
> java.util.Set<Integer> intergersSet = Collections.emptySet();
>
> java.util.Set<String> stringsSet = Collections.emptySet();
>
>
>
> java.util.Map<String, Integer> map = Collections.emptyMap();
>
> java.util.Map<String, String> map2 = Collections.emptyMap();
>
>
>
> List<Long> longs = java.util.Arrays.asList(1L, 2L, 3L);
>
> List<Integer> ints = java.util.Arrays.asList(1, 2, 4);
>
>
>
>
>
> I can do something like this and still the Java language :)
>
>
>
>
>
>
>
>
>
--
>
Otávio Gonçalves de Santana
>
>
blog: http://otaviosantana.blogspot.com.br/
>
twitter: http://twitter.com/otaviojava
>
site: *http://about.me/otaviojava <http://about.me/otaviojava>*
>
55 (11) 98255-3513
>
>
--
Otávio Gonçalves de Santana
blog:
http://otaviosantana.blogspot.com.br/
twitter:
http://twitter.com/otaviojava
site: *
http://about.me/otaviojava <
http://about.me/otaviojava>*
55 (11) 98255-3513