fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Product {
  8.  
  9. }
  10.  
  11. class Order{
  12. public List<Product> products = java.util.Arrays.asList(new Product[4]);
  13. }
  14.  
  15. /* Name of the class has to be "Main" only if the class is public. */
  16. class Main
  17. {
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. Order o = new Order();
  21. o.products.set(0, new Product());
  22. System.out.println(o.products);
  23. o.products.add(new Product()); // throws UnsuportedOperationException
  24. }
  25. }
Runtime error #stdin #stdout #stderr 0.11s 320512KB
stdin
Standard input is empty
stdout
[Product@25154f, null, null, null]
stderr
Exception in thread "main" java.lang.UnsupportedOperationException
	at java.util.AbstractList.add(AbstractList.java:148)
	at java.util.AbstractList.add(AbstractList.java:108)
	at Main.main(Main.java:23)