rspec/rules/S7198/java/rule.adoc

30 lines
749 B
Plaintext

== Why is this an issue?
`Path.of()` provides a modern and consistent approach to creating Path instances, aligning with factory methods such as `List.of()` and `Set.of()`.
Additionally, `Paths.get()` may be deprecated in future versions of Java.
== How to fix it
Replace `Paths.get()` with `Path.of()`.
=== Code examples
==== Noncompliant code example
[source,java,diff-id=1,diff-type=noncompliant]
----
Path path = Paths.get("my/file.txt"); // non compliant
----
==== Compliant solution
[source,java,diff-id=1,diff-type=compliant]
----
Path path = Path.of("my/file.txt"); // compliant
----
== Resources
=== Documentation
- Java Documentation - https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Paths.html[Paths]