• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why not array of parameterized type?

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



Please tell the reason behind!

EDIT: [Question corrected!]
Thanks,
cmbhatt

[ April 24, 2007: Message edited by: Chandra Bhatt ]
[ April 24, 2007: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from my knowledge ,

its like this :


List<String> lst = new ArrayList<String>[10];

one list reference cannot hold 10 arrayList
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chandra,

List<String> lst = new ArrayList<String>[10]; //compiler error, WHY?

Correction to your question:

List<String>[] lst = new ArrayList<String>[10]; //compiler error, WHY?


Here the Thing is Array's will remebers the type of element at runtime. Thats why They can throw ArrayStoreExxption when ever any mismatch found.
Like

Animal [] a = new Dog[10];
a[0] =new Cat(); // This Throws ArrayStoreException why becuase Arrays will rememer the type at runtime.


But

In case genric arrays. Array behavior will be compromised. Which is restricted by compiler. In case of genric arrays "ArrayStoreException" can't be thrown bec'ze of type erasure for generics. Thats why the creation of genric arrays was restricted at compile time
[ April 24, 2007: Message edited by: Srinivasan thoyyeti ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Here the Thing is Array's will remebers the type of element at runtime. Thats why They can throw ArrayStoreExxption when ever any mismatch found.




In case genric arrays. Array behavior will be compromised. Which is restricted by compiler. In case of genric arrays "ArrayStoreException" can't be thrown bec'ze of type erasure for generics.



Wow Srini,
Have this "beer" . Its for you!



Thanks,
cmbhatt
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Angelika Langer's Generics FAQ
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This:

Animal [] a = new Dog[10];
a.add(new Cat()); // This Throws ArrayStoreException why becuase Arrays will rememer the type at runtime.



looks like nonsense to me.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, it's been changed.
reply
    Bookmark Topic Watch Topic
  • New Topic