0

Obviously since Path is an interface it cannot be instantiated by using the new keyword and so we use Path.get() to create a path from a string. But what kind of object is this, it can't be a path object can it because Path is an interface, but when I call the .getClass().getCanonicalName() method I get some cryptic "sun.nio.fs.WindowsPath" response which doesn't answer anything since I can't instantiate this either

edit : after playing around with the runnable interface I found it is quite easy to use a method to create an implementation of an interface and therefore I would like to clarify my question somewhat. When you create an instance of an object that extends an interface you are creating an instance of that object e.g. An object from class Bar is a Bar object even if it extends the interface Foo. But say I write an implementation for an Interface Foo without writing a class that extends it ; my question is what kind of object is this?

public Interface Foo { public void doStuff();}

Then in main:

Foo foo1 = new Foo(){

 public void doStuff(){
// code goes here 
  }
};

What kind of object is foo1?

Moyo2k
  • 137
  • 6
  • Sounds like the implementation is based on the runtime and operating system you are using (since Java can be run on many different things). Could you let us know why you need to instantiate anything, and maybe we can help with the root of the problem? – Jason Sep 07 '14 at 23:07
  • 1
    You don't need to instantiate it. That's what Paths.get() is for. – user207421 Sep 07 '14 at 23:08
  • 2
    [How are Anonymous (inner) classes used in Java?](http://stackoverflow.com/questions/355167/how-are-anonymous-inner-classes-used-in-java) – Sotirios Delimanolis Sep 07 '14 at 23:24
  • Hi my question is more one of understanding a concept since I know what anonymous inner classes are. I want to understand what type of object this anonymously inner class creates? Is it of the type of the interface? – Moyo2k Sep 07 '14 at 23:28
  • It is an instance of what you so vaguely describe as 'some cryptic "sun.nio.fs.WindowsPath" response'. Improve the question and I'll improve the answer. If you only need understanding, that's the answer. If you think you need to instantiate it yourself, you're mistaken. – user207421 Sep 07 '14 at 23:28

1 Answers1

0

The Path is obtained by invoking the getPath method of the default FileSystem.

See also http://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystems.html#getDefault%28%29

John Hascall
  • 9,176
  • 6
  • 48
  • 72