Welcome! Please see the About page for a little more info on how this works.

0 votes
in Java Interop by

In JDK 9 a new nested class Runtime.Version has been introduced.
However, I cannot use it without using the fully qualified name:

(Runtime$Version/parse (System/getProperty "java.version"))
Syntax error compiling at ...
No such namespace: Runtime$Version

;; fully qualified name works
(java.lang.Runtime$Version/parse (System/getProperty "java.version"))
#object[java.lang.Runtime$Version 0x39a4ea03 "11.0.2"]

Is this intended?
I quickly tried this with another (private) nested class and it's the same behavior:

String$CaseInsensitiveComparator
Syntax error compiling ...
Unable to resolve symbol: String$CaseInsensitiveComparator in this context

The Java Interop reference says that nested classes can be accessed as Classname$NestedClassName and doesn't mention this issue specifically.
It does look a bit inconsistent to me.

To be fair, I can still import the nested class and use it - but this is something I didn't expect I had to do:

(import 'java.lang.Runtime$Version)
(Runtime$Version/parse (System/getProperty "java.version"))
#object[java.lang.Runtime$Version 0x781187fa "11.0.2"]

1 Answer

+1 vote
by
selected by
 
Best answer

You can see the list of default imports here: https://github.com/clojure/clojure/blob/clojure-1.11.1/src/jvm/clojure/lang/RT.java#L39

I only see 2 nested classes: Thread$UncaughtExceptionHandler and Thread$State

It's static so I guess it should only include classes that are available in every supported java versions.

...