fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.stream.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. }
  15. }
  16.  
  17. enum MyEnum {
  18. VALUE_1("Super"),
  19. VALUE_2("Rainbow"),
  20. VALUE_3("Dash"),
  21. VALUE_4("Rocks");
  22.  
  23. private final String value;
  24.  
  25. MyEnum(String value) {
  26. this.value = value;
  27. }
  28.  
  29. /**
  30.   * @return the Enum representation for the given string.
  31.   * @throws IllegalArgumentException if unknown string.
  32.   */
  33. public static MyEnum valueOf(String s) throws IllegalArgumentException {
  34. return Arrays.stream(MyEnum.values())
  35. .filter(v -> v.value.equals(s))
  36. .findFirst()
  37. .orElseThrow(() -> new IllegalArgumentException("unknown value: " + s));
  38. }
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:33: error: method valueOf(String) is already defined in enum MyEnum
    public static MyEnum valueOf(String s) throws IllegalArgumentException {
                         ^
1 error
stdout
Standard output is empty