JavaN3wb
JavaN3wb

Reputation: 17

Can't Access Imported Class Method

I am trying to create a new Path using the following method:

Path path = new Paths.get(path_name);

I've imported both Path and Paths and I have confirmed that the method get exists in Paths, but Eclipse is telling me that the method does not exist. It says: Paths.get cannot be resolved to a type What should I do? I restarted Eclipse and my PC but still no luck. Thanks in advance.

Upvotes: 1

Views: 1054

Answers (2)

MrSmith42
MrSmith42

Reputation: 10151

get(..) is a static method. Call it like this:

Path path = Paths.get(path_name);

Cite: 'This class consists exclusively of static methods' API

Upvotes: 4

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726479

Your code snippet is incorrect: invoking a static method does not require new

Path path = Paths.get(path_name); // get(...) is a static method

Upvotes: 2

Related Questions