Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

Editing Snippet ID: #1036530
Snippet name:
Category, Type:
Content:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// We store the element type as the type of the internal array.
// Disadvantage: Empty lists are a bit bigger.
// Methods will throw ArrayStoreException if trying to add
// element of wrong type.
persistable sclass SynchronizedTypedArrayList<A> extends Synchroni
zedArrayList_Base<A> implements RandomAccess, Cloneable {
  private static final int DEFAULT_CAPACITY = 10;
  transient Object[] elementData; // non-private to simplify 
nested class access
  private int size;
  
  private *() {} // for persistence only - sadly this doesn't 
actually restrict access since we're an inner class
  *(Class<A> elementType) {
    this(elementType, 0);
  }
  
  *(Class<A> elementType, int initialCapacity) {
      if (initialCapacity >= 0)
        elementData = newArray(elementType, initialCapacity);
      else
        throw new IllegalArgumentException("Illegal Capacity: "+
          initialCapacity);
  }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Comment:
Public (visible to everyone):
Created: 2023-01-23 14:49:08

This page without fancy editor.