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:06:44 -0300
Martin.
Is there any place in the new JavaSE API that does something like you
propose to do?
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 - the reality is
>
not an absence of relationship. The reality is a relationship that we can
>
not express in Java.
>
>
>
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