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. private class Foo {
  11. int foo;
  12. Foo(int foo) {
  13. this.foo = foo;
  14. }
  15. }
  16. public static void main (String[] args) throws java.lang.Exception
  17. {
  18. HashMap<Long, Foo> map = new HashMap<>(){{
  19. put(0, new Foo(3));
  20. put(1, new Foo(5));
  21. put(2, new Foo(2));
  22. }};
  23.  
  24. Comparator<Foo> comp = (lhs, rhs) -> Integer.compare(lhs.foo, rhs.foo);
  25. map
  26. .stream()
  27. .sortedBy(comp)
  28. .forEach(foo -> System.out.println("Got ", foo.foo));
  29. }
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:18: error: cannot infer type arguments for HashMap<K,V>
		HashMap<Long, Foo> map = new HashMap<>(){{
		                                    ^
  reason: cannot use '<>' with anonymous inner classes
  where K,V are type-variables:
    K extends Object declared in class HashMap
    V extends Object declared in class HashMap
Main.java:26: error: cannot find symbol
			.stream()
			^
  symbol:   method stream()
  location: variable map of type HashMap<Long,Ideone.Foo>
2 errors
stdout
Standard output is empty