0

The isAbsolute method does not have a body in the path interface, but I can run it in the following code. How is this possible?

Path path= Paths.get("D:\\Example\\1.txt");
    System.out.println(path.isAbsolute());//prints true
3

1 Answer 1

0

Imagine following code:

public interface Foo {
  public boolean bar();
}

public class Fooz implements Foo {
  @Override
  public boolean bar() {
    return false;
  }
}

And:

public Foo getFoo() {
  return new Fooz();
}

public static void main(String[] args) {
  Foo myFoo = getFoo();
  System.out.println(myFoo.bar()) //false
}

If you are looking for actual implementation of this function, I advise looking thru the source code of JVM of your choosing. Example of one such implementation can be found in UnixPath.java on OpenJDK github repo.

Sign up to request clarification or add additional context in comments.

3 Comments

I understand what you mean, but the problem is that if you follow this method, the method will not work. Paths.get () Returns the Path.of () method. The of() method is also returns FileSystems.getDefault ( ) .getPath (first, more). getDefault () itself Returns a FileSystem object that calls the getPath () method. This method returns a Path object, but it is not yet clear how the isAbsolute method is implemented.
What do you mean the method will not work? Your question seems to indicate that you wanted to know how it was even possible to call isAbsolute, but are you actually looking for the source code of the implementation of isAbsolute?
Yes, that's what I mean. I want to know how this is implemented.[looking for source code]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.