fork(1) download
  1.  
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  5.  
  6. class Country {
  7. static final Set<String> EXISTING = new HashSet<String>();
  8.  
  9. final String name;
  10.  
  11. Country(String name) {
  12. if(EXISTING.contains(name))
  13. throw new IllegalArgumentException(name + " already exists!");
  14.  
  15. this.name = name;
  16. EXISTING.add(name);
  17. }
  18.  
  19. public static void main (String[] args) {
  20. Country oldSweden = new Country("Sweden");
  21.  
  22. try {
  23. Country newSweden = new Country("Sweden");
  24. } catch(IllegalArgumentException iae) {
  25. System.out.println(iae.getMessage());
  26. }
  27. }
  28. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Sweden already exists!