Page 1 of 1

About question enthuware.ocpjp.v8.2.1543 :

Posted: Wed Mar 09, 2016 4:58 pm
by javalass
This is not correct. These attributes are supported by BasicFileAttributes, not BasicFileAttributeView.

Re: About question enthuware.ocpjp.v8.2.1543 :

Posted: Wed Mar 09, 2016 5:31 pm
by javalass
Same problem on question enthuware.ocpjp.v8.2.1777.

Re: About question enthuware.ocpjp.v8.2.1543 :

Posted: Wed Mar 09, 2016 11:40 pm
by admin
While BasicFileAttributes indeed defines the constants, the attributes of a given file are provided by "views", which in this case is BasicFileAttributeView. If a file system implements a particular "view", it must provide the values of the attributes supported by that view.

Explained here:
https://docs.oracle.com/javase/7/docs/a ... eView.html
or
https://docs.oracle.com/javase/8/docs/a ... eView.html

Re: About question enthuware.ocpjp.v8.2.1543 :

Posted: Thu Mar 10, 2016 10:00 am
by javalass
You're correct, that's what the documentation says.

I still don't understand it though. BasicFileAttributeView only has 3 methods: name(), readAttributes() and setTimes(). BasicFileAttributes defines methods which return the attributes in question: isDirectory(), LastAccessedTime(), creationTime() and so on. The usual way to access these attributes by calling readAttributes() on a BasicFileAttributeView, then calling isFile(), isDirectory(), etc, on the BasicFileAttributes instance returned.

Now why does the documentation say that it's the BasicFileAttributeView that supports these attributes, not BasicFileAttributes? :(

Re: About question enthuware.ocpjp.v8.2.1543 :

Posted: Thu Mar 10, 2016 9:55 pm
by admin
I think it is just a matter of interpretation. BasicFileAttributes is a conduit that allows you to retrieve the attribute values but the support for the values is actually provided by the underlying view, which is BasicFileAttributeView.

It is same as saying, "which attributes are supported by a Posix based file system?" Would you argue here that the attributes are supported by PosixFileAttributes and not by the file system?

I don't think it is a big issue here because the question is purely theoretical and not code based. Of course, if you were presented with a code snippet that contained BasicFileAttributeView.creationTime() or something, that would have been incorrect.

HTH,
Paul.