Notes on implementing concise calls to constructors with type parameters
Ulf Zibis
Ulf.Zibis at gmx.de
Thu May 14 07:00:25 PDT 2009
Am 14.05.2009 12:55, Neal Gafter schrieb:
> On Thu, May 14, 2009 at 2:00 AM, Maurizio Cimadamore <
> Maurizio.Cimadamore at sun.com> wrote:
>
>
>> Let me start by saying that all the examples I found in this thread
>> exploits inference from the return type.
>>
>
>
> If you're looking for an example, given
>
> *class X<T> {*
> * public X(T t) { ... }*
> *}*
>
> *void f(X<String> xs) ...*
>
> the code
>
> *f(new X<>("foo"))*
>
This is the only case, where I think, that typed constructors make
sense, as making things clear, but it should only be mandatory, if
otherwise syntax is ambiguous.
For normal cases, I agree Howard: I'm not a fan of the <> syntax.
In above case, we can see parameter definition of f in same semantics as
normal type definition, so f(new X("foo")) should suffice.
What should the code
f(new X<>("foo"))
mean, if we have? :
class X<T> {
public X(String s) { ... }
public X(int i) { ... }
}
I only see need for typed constructors in case of anonymous
instantiation (here Comparator):
SortedSet<Map.Entry<Byte,Character>> valueSorted = new
TreeSet(new Comparator<Map.Entry<Byte,Character>>() {
public int compare(Map.Entry<Byte,Character> e1,
Map.Entry<Byte,Character> e2) {
return (e1.getValue() < e2.getValue()) ? -1 :
(e1.getValue() > e2.getValue()) ? 1 :
((e1.getKey()&0xFF) < (e2.getKey()&0xFF)) ? -1 :
((e1.getKey()&0xFF) > (e2.getKey()&0xFF)) ?
1 : 0;
}
});
-Ulf
More information about the coin-dev
mailing list