0
Path path=Paths.get("...."); //Path interface not class

Another question: Do we need to implement all the methods of path interface listed in the java oracle documentation when we create a class which implements the path interface ?

  • `Paths.get` does `return new MagicPathImpl()`. – Boris the Spider Oct 09 '16 at 11:11
  • 1) That method returns instance of class which implements Path interface (you can't instantiate interface, you can instantiate only classes - non-abstract ones), 2) yes, non-abstract class must ensure that all methods will know how to behave, so it needs to provide or inherit from somewhere their implementation. – Pshemo Oct 09 '16 at 11:11
  • @Pshemo Does that means that the description of methods shown in the path interface page in oracle documentation is actually the method implementation done in the instance of class which implements Path interface ? – Bacterio Vevo Oct 09 '16 at 11:16
  • To be able to use `InterfaceName reference = new SomeClass();` (like `List lines = new ArrayList<>();`) it must be ensured that any `reference.method()` can be safely called (where `method()` belongs to `InterfaceName`). This means that `SomeClass` must *provide* implementation for any `method()`. – Pshemo Oct 09 '16 at 11:32

0 Answers0