Skip to content

Instantly share code, notes, and snippets.

@wwarlock
Created April 26, 2017 15:09
Show Gist options
  • Save wwarlock/31e4407ef02d6c2e5527fa326fecc929 to your computer and use it in GitHub Desktop.
Save wwarlock/31e4407ef02d6c2e5527fa326fecc929 to your computer and use it in GitHub Desktop.
import java.util.*;
public class ComputeIfAbsent {
public static void main(String[] args) {
Map map = new LinkedHashMap();
map.computeIfAbsent(42, ArrayList::new);
}
}
@wwarlock
Copy link
Author

That code doesn't compile and gives the error
ComputeIfAbsent.java:7: error: incompatible types: invalid constructor reference

@kabutz
Copy link

kabutz commented Apr 26, 2017

Of course, since there is no ArrayList with constructor taking an Object as parameter :-)

@wwarlock
Copy link
Author

But as you said that is the correct answer.
Am I misunderstood something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment