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

0 votes
in Java Interop by

Now that Clojure 1.10 alpha-6 dropped support for Java <=7, it seems reasonable to add the classes that were newly introduced to the {{java.lang}} package in Java <=8, into Clojure's {{DEFAULT_IMPORTS}}.

Here is the list of those classes I'm aware of:

Introduced in Java 7:
- AutoCloseable
- ClassValue
- ReflectiveOperationException
- BootstrapMethodError
- SafeVarargs

Introduced in Java 8:
- FunctionalInterface

Prescreened by: Alex Miller

5 Answers

0 votes
by

Comment made by: gshayban

Besides AutoCloseable, the rest of those classes are rarely used. I'd rather import them explicitly over polluting the ns imports tbh. (Interfaces annotated with FunctionalInterface, an annotation type, are common; using it explicitly isn't)

There is a minor startup time cost to additional classloading, for classes not already loaded by the java.base module. I've experimented with dropping a bunch of rarely used default imports (a breaking change, no doubt).

0 votes
by

Comment made by: alexmiller

I think we should uphold what has been true and stated in the past - stuff in java.lang is auto-imported. I do not think autoimporting 6 classes will affect startup time.

0 votes
by

Comment made by: sohta

Added the patch, just in case :)

0 votes
by

Comment made by: glts

Several nested classes in {{java.lang}} are also not yet auto-imported. Some of them are though:

`
Thread$UncaughtExceptionHandler
; => java.lang.Thread$UncaughtExceptionHandler

Character$Subset
; Syntax error compiling at (REPL:0:0).
; Unable to resolve symbol: Character$Subset in this context
`

The missing imports are the following:

  • {{Character$Subset}}
  • `}

  • {{ProcessBuilder$Redirect}}
  • `

  • {{ProcessBuilder$Redirect$Type}}

Perhaps it would be good to add those here as well. At least I was surprised not being able to use bare
`}.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2383 (reported by sohta)
...