Is it a bug of Clojure 1.10.0-alpha8?

is it a bug of Clojure 1.10.0-alpha8?

(import 'java.sql.Date)
(import 'java.util.Date)

Exception in thread “main” Syntax error compiling at
Cause: Date already refers to: class java.sql.Date

(ns t 
  (:import [java.sql JDBCType Types Date] 
           [java.util.Date]))

Caused by: clojure.lang.ExceptionInfo:
Call to clojure.core/ns did not conform to spec.

No, I don’t think [java.util.Date] was ever valid. The vector is used to specify [<ns> <class>...] so without any classes its just have an empty ns prefix that doesn’t do anything. At least thats how it works in CLJS but I think the same applies for CLJ.

You can just specify java.util.Date without the vector.

(import 'java.sql.Date)
(import 'java.util.Date)

Exception in thread “main” Syntax error compiling at
Cause: Date already refers to: class java.sql.Date

In the JVM’s ecosystem, the project cannot guarantee that the class names introduced are unique, so I think it is a bug.

Yes, but importing two classes by the same name never worked? That is not new in 1.10, only the extra ns validation.

You can just use the fully qualified name directly without import though.

(java.sql.Date. 0)

Thanks, I mistakenly thought that I need to import the class before I can use it.

Ah, no, importing is just a way to give you a shorthand way of referring to a class, that is saying “when I type Date, read it as java.sql.Date”.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.