On Sat, Oct 4, 2008 at 9:25 AM, Daniel Cheng <[EMAIL PROTECTED]> wrote:
> On Sat, Oct 4, 2008 at 12:37 AM, Matthew Toseland
> <[EMAIL PROTECTED]> wrote:
>> On Thursday 02 October 2008 12:30, [EMAIL PROTECTED] wrote:
>>> Author: j16sdiz
>>> Date: 2008-10-02 11:30:51 +0000 (Thu, 02 Oct 2008)
>>> New Revision: 22908
>>>
>>> Modified:
>>>    trunk/freenet/src/freenet/support/MultiValueTable.java
>>> Log:
>>> Generic for MultiValueTable
>>>
>>> Modified: trunk/freenet/src/freenet/support/MultiValueTable.java
>>> ===================================================================
>>> --- trunk/freenet/src/freenet/support/MultiValueTable.java    2008-10-01
>> 21:59:33 UTC (rev 22907)
>>> +++ trunk/freenet/src/freenet/support/MultiValueTable.java    2008-10-02
>> 11:30:51 UTC (rev 22908)
>> ...
>>>
>>> -    public Object[] getArray(Object key) {
>>> +    public V[] getArray(K key) {
>>>          synchronized (table) {
>>> -            Vector v = (Vector) table.get(key);
>>> +            Vector<V> v = table.get(key);
>>>              if (v == null)
>>>                  return null;
>>>              else {
>>> -                Object[] r = new Object[v.size()];
>>> +                V[] r = (V[])new Object[v.size()];
>>
>> This doesn't work.
>
> This does not work for normal array.
> A generic V[] is a Object[] in its underlying structure.
>
> (yes, that's why people hate java generic -- too many special cases)
>


Okay, I was wrong. That line of code does not throw, but it would throw later:


  1 public class Test<X> {
  2     X[] x;
  3     public Test() { x = (X[]) new Object[]{}; }
  4     public X[] get() { return x; }
  5
  6     public static void main(String[] arg) {
  7         String[] y = new Test<String>().get();
  8
  9         System.out.println(y);
 10     }
 11 }

this throw at line 7, (not line 3 or 4)

>>
>> bsh % Object[] objects = new Object[5];
>> bsh % Long[] longs = (Long[]) objects;
>> // Error: // Uncaught Exception: Typed variable declaration : at Line: 2 : in
>> file: <unknown file> : ( Long [ ] ) objects
>>
>> Target exception: java.lang.ClassCastException: Cannot cast java.lang.Object
>> [] to java.lang.Long []
>>
>> bsh % Long[] longs = (Long[]) objects;
>>
>>
>>>                  v.copyInto(r);
>>>                  return r;
>>>              }
>>>          }
>>>      }
>>>
>>
>> _______________________________________________
>> Devl mailing list
>> [email protected]
>> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl
>>
>
_______________________________________________
Devl mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl

Reply via email to