fork download
  1. class Bag<T> {
  2.  
  3. private T[] cards;
  4.  
  5. public Bag() {
  6. this.cards = (T[]) new Object[10];
  7. }
  8.  
  9. public void set(int index, T value) {
  10. this.cards[index] = value;
  11. }
  12.  
  13. @Override
  14. public String toString() {
  15. return "Bag{cards=" + java.util.Arrays.toString(cards) + "}";
  16. }
  17.  
  18. public static void main(String[] args) {
  19. Bag<Integer> bag = new Bag<Integer>();
  20. bag.set(0, 10);
  21. bag.set(1, 20);
  22. bag.set(2, 30);
  23. System.out.println(bag);
  24. }
  25. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
Bag{cards=[10, 20, 30, null, null, null, null, null, null, null]}