I think the title says it all. How would I specify FOLLOW_LINKS? Why create an enum with just one option? For example, the method java.nio.file.Files.getLastModifiedTime(Path, LinkOption...) takes an array of LinkOption-s as argument. You have to pass something, yet you can only pass the one option available. This surprised me, and would like to know more about it.
Following links is the default behavior. I.e., if you don't specify NOFOLLOW_LINKS, then links are followed.
From the documentation of the Files.getLastModifiedTime()
method (emphasis mine):
The options array may be used to indicate how symbolic links are handled for the case that the file is a symbolic link. By default, symbolic links are followed and the file attribute of the final target of the link is read. If the option NOFOLLOW_LINKS is present then symbolic links are not followed.
LinkOption
documentation mentioned that following links is the default behavior for calls where LinkOption
is used. –
Palladian What confused me a bit is that the LinkOptions argument to Files.exists() is a vararg argument , a fact I did not recognize immediately... you may just leave it away. Setting it to null will give an exception.
Many of the NIO.2 methods use a varargs for passing options, even when there is only one enum value available. The advantage of this approach, as opposed to say just passing a boolean argument, is future-proofing. These method signatures are insulated from changes in the Java language down the road when future options are available.
cited from "OCP Oracle Certified Professional Java SE 11 Programmer II"
© 2022 - 2024 — McMap. All rights reserved.