On 12/06/2011 08:07 AM, David Holmes wrote:
On 6/12/2011 12:14 PM, David Holmes wrote:
On 6/12/2011 11:45 AM, Rémi Forax wrote:
On 12/06/2011 02:12 AM, David Holmes wrote:
Is the reason for constructs like this:

HashEntry<K,V>[] tab = (HashEntry<K,V>[])new HashEntry<?,?>[cap];

that we can't utilize diamond? Otherwise it would nicely reduce to:

HashEntry<K,V>[] tab = new HashEntry<>[cap];

This should not compile because otherwise you can write

This compiles fine:

@SuppressWarnings("unchecked")
public class TestGenerics<K,V> {

static class HashEntry<K,V> { }

public void m() {
HashEntry<K,V>[] newTable = new HashEntry<>[1];
}
}


I don't know exactly what the type inference code does but I assumed it
effectively converted the above to:

HashEntry<K,V>[] newTable = (HashEntry<K,V>[]) new HashEntry[1];

and not to:

HashEntry<K,V>[] newTable = new HashEntry<K,V>[1];

which of course does not compile.

Hmmm. Perhaps this is a compilation accident? I don't see anything in the spec that allows diamond to be used with array creation expressions.

Yes, it's a bug of javac, eclipse compiler rejects this code.


David
-----

Rémi

Reply via email to