Path.of() factory
Home / I/O / Path.of() factory
Code Comparison
Path path = Paths.get("src", "main",
"java", "App.java");
var path = Path.of("src", "main",
"java", "App.java");
Why the modern way wins
๐
Consistent API
Follows the .of() factory pattern like List.of(), Set.of().
๐
Discoverable
Found on the Path type itself, not a separate Paths class.
๐งน
One less class
No need to import the Paths utility class.
Modern Approach
Path.of()
JDK Support
Path.of() factory
Available
Widely available since JDK 11 (Sept 2018)
How it works
Path.of() is a factory method added directly to the Path interface, replacing the separate Paths utility class. It's more discoverable and consistent with List.of(), Map.of(), etc.
Related Documentation
Proof