Path.of() factory
Use Path.of() — the modern factory method on the Path interface.
Porównanie kodu
✕ Java 8
Path path = Paths.get("src", "main",
"java", "App.java");
✓ Java 11+
var path = Path.of("src", "main",
"java", "App.java");
Widzisz problem z tym kodem? Daj nam znać.
Dlaczego nowoczesne podejście wygrywa
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.
Stare podejście
Paths.get()
Nowoczesne podejście
Path.of()
Od JDK
11
Poziom trudności
Początkujący
Wsparcie JDK
Path.of() factory
Dostępne
Widely available since JDK 11 (Sept 2018)
Jak to działa
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.
Powiązana dokumentacja