0
import java.util.function.Consumer;

public class test {
    public static void main(String[] args) {
        Consumer<String> c = (x) --> System.out.println(x.toLowerCase());
        c.accept("Java2s.com");
    }
}

with error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: x cannot be resolved to a variable x cannot be resolved at test.main(test.java:5)

But in all official documents, this is working... Could someone help me?

xuhdev
  • 8,018
  • 2
  • 41
  • 69
Shadow
  • 5
  • 1
  • 5

1 Answers1

6

Change --> to -> and it should work. It would work only in java8 and later. It's a way to define lambda expression which would consume a string (in your case) and would change the case to lower.

SMA
  • 36,381
  • 8
  • 49
  • 73
  • 1
    Thank, but when i changed it, it also mention with the same error and told me i need to change -> to --> – Shadow Jan 03 '16 at 21:35