I/O Początkujący

Use Path.of() — the modern factory method on the Path interface.

✕ 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ć.
📐

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
Path.of() factory
Dostępne

Widely available since JDK 11 (Sept 2018)

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.

Udostępnij 𝕏 🦋 in