• 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

generics in arrays

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got this from javabeat.net

35)What is the correct option for questions mark?
List<String> arr[] = ?
a)new ArrayList();
b)new ArrayList<String>();
c)new ArrayList[10];
d)null;
e)new ArrayList<Object>();

Ans 35)C and D
Explanation:
Since the Reference is of type Array, it will hold only array declaration of List (or) its
subtype


Is this valid question, because as far as i know we cannot create array have comonenents of generic class.
Kindly clear my doubt.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Geeta you are right that you cannot have arrays of Generic types, but statement C is creating an array of Raw ArrayList. So it will compile with a warning. To be more specific, you can write this

List<MyClass>[] arr;

but you cannot write this

new ArrayList<MyClass>[5];
reply
    Bookmark Topic Watch Topic
  • New Topic