0

I recently installed JDK 8 on my Eclipse (MAC) and I m trying to use the streams.

However, it seems that Java 8 is not correctly configured since I get the following error on the following line of code:

List<Eshop> tempShops = eshops.stream().filter( e -> e.getName().equals(name)).collect(Collectors.toList());

Multiple markers at this line
    - e cannot be resolved to a variable
    - e cannot be resolved
    - Syntax error on token "-", -- 
     expected

Anybody has an idea what might be wrong?

EDIT Also tried like

List<Eshop> tempShops = eshops.stream().filter( (e) -> e.getName().equals(name)).collect(Collectors.toList());
panipsilos
  • 2,219
  • 11
  • 37
  • 53
  • Looks like you're using `args -> expression`. It should be `(args) -> expression`. – Nissa Oct 04 '16 at 12:50
  • Hi, could u please be more specific? What do you mean by (args)? can you give an example? – panipsilos Oct 04 '16 at 12:55
  • As in, you need parentheses around your lambda arguments. See [Introduction to Java Lambdas](/documentation/java/91/lambda-expressions/2353/introduction-to-java-lambdas). – Nissa Oct 04 '16 at 12:59
  • I edited my questions, I also tried adding (e), but still I get the error. Besides anywere in the web they dont use parentheses, e.g. http://winterbe.com/posts/2014/07/31/java8-stream-tutorial-examples/ – panipsilos Oct 04 '16 at 13:02
  • What version of Eclipse are you using? – Nissa Oct 04 '16 at 13:04
  • Eclipse Java EE IDE for Web Developers. Version: Kepler Service Release 2 Build id: 20140224-0627 and I m using MAC – panipsilos Oct 04 '16 at 13:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124896/discussion-between-panipsilos-and-some-person). – panipsilos Oct 04 '16 at 13:05
  • Have you set the right JDK in eclipse? http://stackoverflow.com/questions/13635563/setting-jdk-in-eclipse – Ash Oct 04 '16 at 13:09
  • 1
    @SomePerson parenthesis are not needed for single arguments without a type – Thorbjørn Ravn Andersen Oct 04 '16 at 15:01

2 Answers2

3

Eclipse Kepler did not contain Java 8 support (unless you installed a patch).

You should use the current Eclipse Neon (4.6.1) for full Java 8 support.

greg-449
  • 109,219
  • 232
  • 102
  • 145
0

I had the same problem. I created a predicate separately and the java.util.function.Predicate package got auto imported and the error was resolved.

You could try something like this:

Predicate shop = e -> {return e.getName().equals(name);};

List tempShops = eshops.stream().filter(shop).collect(Collectors.toList());

Neha
  • 1