Use Advanced Search to search the entire archive.
Re: Remove "generic" multiply/divide operations from Quantity
- From: Martin Desruisseaux <
>
- To:
- Subject: Re: Remove "generic" multiply/divide operations from Quantity
- Date: Fri, 17 Oct 2014 10:03:55 +0900
- Organization: Geomatys
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 :)