Hi,
The issue is that
Path.of(String) method doesn't actually exist, your
link was to
Path.of(String, String...) which is syntactic sugar for a method with a signature of
Path.of(String, String[]). So when you try to call
Path.of(String) py4j correctly reports that there is no such method.
Therefore you need to pass an empty array as the second parameter like this:
>>> p = gateway.jvm.java.nio.file.Path.of("/tmp/my/../path", gateway.new_array(gateway.jvm.java.lang.String, 0))
And then you can call methods on p as expected.
>>> p.normalize().toString()
'/tmp/path'
>>> p.toString()
'/tmp/my/../path'
It follows that you can't do this either as there is no method with that signature either:
>>> p = gateway.jvm.java.nio.file.Path.of("/part1", "part2", "part3", "part4")
Instead do this:
>>> more = gateway.new_array(gateway.jvm.java.lang.String, 3)
>>> more[0] = "part2"
>>> more[1] = "part3"
>>> more[2] = "part4"
>>> p = gateway.jvm.java.nio.file.Path.of("/part1", more)
>>> p.toString()
'/part1/part2/part3/part4'
To slightly complicate matters, Java collections actually does have a List.of(E) method, and List.of(E, E), and List.of(E, E, E), etc and finally List.of(E[]). Which means you need to know a bit more details about the APIs when calling from Python than you would if you used Java directly:
>>> p = gateway.jvm.java.util.List.of("/part1", "part2", "part3", "part4")
>>> p.toString()
'[/part1, part2, part3, part4]'
But if you want to call the List.of(E[]) version you need to use an Object array:
>>> more = gateway.new_array(gateway.jvm.java.lang.Object, 3)
>>> more[0] = "part2"
>>> more[1] = "part3"
>>> more[2] = "part4"
>>> p = gateway.jvm.java.util.List.of(more)
>>> p.toString()
'[part2, part3, part4]'
HTH
Jonah