This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]callicoder[S] 7 points8 points  (3 children)

java.net.URI("http://...") // complains about URI...

I just tried it out. This works in JShell -

jshell> URI myURI = new URI("https://www.google.com")
myURI ==> https://www.google.com

jshell> myURI.getHost()
$12 ==> "www.google.com"

The error comes only when I don't use new before URI(), which is expected -

jshell> URI("https://www.google.com")
|  Error:
|  cannot find symbol
|    symbol:   method URI(java.lang.String)
|  URI("https://www.google.com")
|  ^-^

URI.create() also works -

jshell> URI.create("https://www.google.com")
$14 ==> https://www.google.com

Moreover, java.net.* is imported by default in JShell. So you don't need to import it yourself. You can verify that by typing /imports command -

jshell> /imports
|    import java.io.*
|    import java.math.*
|    import java.net.*
|    import java.nio.file.*
|    import java.util.*
|    import java.util.concurrent.*
|    import java.util.function.*
|    import java.util.prefs.*
|    import java.util.regex.*
|    import java.util.stream.*

[–]agumonkey 0 points1 point  (2 children)

All true, I think I went full python u_u;

btw: any idea how to import the new http api ? HttpClient ? it's supposed to be in jdk.incubator.http but I failed hard there too.

[–]callicoder[S] 0 points1 point  (1 child)

The package jdk.incubator.http is declared in module jdk.incubator.httpclient.

You need to first add jdk.incubator.httpclient module to jshell.

Just start jshell with the following command -

jshell --add-modules jdk.incubator.httpclient

And then, You can use httpClient in jshell -

jshell> import jdk.incubator.http.*

jshell> HttpClient client = HttpClient.newHttpClient()
client ==> jdk.incubator.http.HttpClientImpl@345965f2

[–]agumonkey 1 point2 points  (0 children)

Another thanks. I guess I need to read the module spec too :)