This question already has an answer here:
I am studying Java at my computer science class and I've found in the examples this line of code:
String name = "test"; Runnable r = () -> System.out.println(name); r.run();
I know what a Runnable does and I also know that it is an interface. By my knowledge I know that it's not possible to create an instance of an interface. But looking at the above code it seems that it's possible to call interface methods.
Are anonymous classes involved here? I have studied that
new Thread(new Runnable()...)
Is not an instance of an interface but it's actually an anonymous class that implements an interface. Does the same happen with the code above? Are anonymous classes involved?