• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generics 1.4

 
rohit kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am getting a runtime error. PLs help
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create a List using asList, the size is fixed.
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because the list is backed by the array, and arrays can't change their size.

But you could make a copy of the list returned by the asList method using
List ints = new ArrayList(
Arrays.asList(new Integer[] {new Integer(1), new Integer(2), new Integer(3)})
);

Then you'll have your six and ten.


By the way, wouldn't be "The Six and Ten" a nice name for a pub?
Bu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic