2
votes

Eclipse gives me content assist on functions. For example String. ctrl+space shows me String.valueOf(), among others.

With a stream and using ::, this does not work, however. For example, new LinkedList<String>().stream().map(String:: ctrl+space does not help me in completing it to new LinkedList<String>().stream().map(String::valueOf);.

Is there some option or plugin to enable this? I use Eclipse Luna (4.4.0).

1

1 Answers

3
votes

Eclipse Luna does include support for method reference syntax, but apparently not in the specific context you're trying. It does work if you declare the method reference as a variable with a specific type, however. Like this:

Function<String, Object> methodRef = String::valueOf;
new LinkedList<String>().stream().map(methodRef);

In this code, content-assist works correctly at the :: point. I suspect this is because Eclipse has more information about the types this way (with the type declared in the variable), as opposed to the in-line syntax of your example.

According to Eclipse bug 430656, this has been fixed for the 4.4.2 release, which is due in February, 2015. Before then you could download an early milestone build of 4.4.2