Here’s the code
Path file = ...;
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
System.out.println("creationTime: " + attr.creationTime());
System.out.println("lastAccessTime: " + attr.lastAccessTime());
System.out.println("lastModifiedTime: " + attr.lastModifiedTime());
At the link
http://docs.oracle.com/javase/tutorial/essential/io/fileAttr.html ,they say BasicFileAttributes is a class. But the link http://docs.oracle.com/javase/7/docs/api/java/nio/file/attribute/BasicFileAttributes.html calls it an interface.(Please clear this confusion if you know, although this isn’t the main problem)
Main Problem:
I can’t understand BasicFileAttributes.class parameter. Are they trying to pass a class as parameter?
BasicFileAttributes is an interface, but it is common in colloquial expression to use the phrase such as “BasicFileAttributes class” to mean “a class that implements BasicFileAttributes”.
As for your main question, you are passing an instance of the special Java class
java.lang.Class. So no, you are not “passing a class in” (that concept is in fact meaningless in Java). You are passing such an instance ofjava.lang.Classthat describes the interfaceBasicFileAttributes.This is similar to when you pass an instance of
Fileto a method: you are not passing the actual file in, but an object through which that file can be managed.