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. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. System.out.println(MC.Type.getValue("MInteger").getName());
  14. System.out.println(MC.Type.getValue("MBoolean").getName());
  15.  
  16.  
  17. }
  18. }
  19.  
  20. interface MC {
  21. public static final Type<Boolean> MBoolean = new Type<>("MBoolean");
  22. public static final Type<Integer> MInteger = new Type<>("MInteger");
  23.  
  24. public static class Type<T> {
  25. private final String name;
  26. private static final Map<String, Type<?>> types = new HashMap<>();
  27. static {
  28. types.put(MBoolean.getName(), MBoolean);
  29. types.put(MInteger.getName(), MInteger);
  30. }
  31. private Type(String name) {
  32. this.name = name;
  33. }
  34.  
  35. public String getName() {
  36. return name;
  37. }
  38.  
  39. public static Type<?> getValue(String name) {
  40. return types.get(name);
  41. }
  42. }
  43. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
MInteger
MBoolean