fork(1) 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.Collectors;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone {
  10. public static void main(String[] args) throws java.lang.Exception {
  11. Map<String, String> map = new HashMap<>();
  12.  
  13. map.put("PLACEHOLDER", "some_data1");
  14. map.put("Google", "some_data2");
  15. map.put("Facebook", "some_data3");
  16. map.put("Microsoft", "some_data4");
  17.  
  18. Random rand = new Random();
  19. boolean condition = rand.nextBoolean();
  20.  
  21. map = map.entrySet()
  22. .stream()
  23. .filter(entry -> "PLACEHOLDER".equals(entry.getKey()))
  24. .map(key -> {
  25. if (condition) {
  26. return "Apple";
  27. } else {
  28. return "Netflix";
  29. }
  30. }).collect(Collectors.toMap(e -> e.getKey(), Map.Entry::getValue));
  31.  
  32. System.out.println(map);
  33. }
  34.  
  35. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:27: error: cannot find symbol
            }).collect(Collectors.toMap(e -> e.getKey(), Map.Entry::getValue));
                                              ^
  symbol:   method getKey()
  location: variable e of type String
Main.java:27: error: incompatible types: cannot infer type-variable(s) CAP#1,T,K#1,U
            }).collect(Collectors.toMap(e -> e.getKey(), Map.Entry::getValue));
                      ^
    (argument mismatch; invalid method reference
      method getValue in interface Entry<K#2,V> cannot be applied to given types
        required: no arguments
        found: String
        reason: actual and formal argument lists differ in length)
  where T,K#1,U,K#2,V are type-variables:
    T extends Object declared in method <T,K#1,U>toMap(Function<? super T,? extends K#1>,Function<? super T,? extends U>)
    K#1 extends Object declared in method <T,K#1,U>toMap(Function<? super T,? extends K#1>,Function<? super T,? extends U>)
    U extends Object declared in method <T,K#1,U>toMap(Function<? super T,? extends K#1>,Function<? super T,? extends U>)
    K#2 extends Object declared in interface Entry
    V extends Object declared in interface Entry
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object from capture of ?
2 errors
stdout
Standard output is empty