Java 8 - Static Method Reference Rule -
i have following piece of code:
public class chap20 { public static void main(string[] args) { string[] names = { "john", "jane" }; stream<string> namesstream = stream.of(names); path path = paths.get("."); stream<path> files; try { files = files.list(path); files.foreach(system.out::println); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
now here´s file.foreach method signature:
void java.util.stream.stream.foreach(consumer<? super path> action)
i´m reading method accepts consumer of type @ least path type or superclass of path, i´m missreading it, since system.out not superclass of path.
can please explain how correct read it?
? super path
says: 'it has super class of path.
system.out.println
accepts object
. object
super class of path
hence correct.
Comments
Post a Comment