3

I'm having a heck of a time trying to figure out how to use the Java interop in Clojure to normalize Unicode. I've been trying to to use java.text.Normalizer, but I keep getting ClassNotFoundException when trying to call the enum Normalizer.Form.NFD. Essentially, I'm just trying to do something like this in Java:

java.text.Normalizer.normalize("Ἑλλάς", java.text.Normalizer.Form.NFD);

I've been trying to do something like this in Clojure, but to no avail:

(import java.text.Normalizer)
(java.text.Normalizer/normalize "Ἑλλάς" java.text.Normalizer.Form/NFD)

Normalizer/normalize seems to be found ok, but getting at Normalizer.Form.NFD seems to be the problem as I keep getting the error:

Caused by java.lang.ClassNotFoundException java.text.Normalizer.Form

I'm working on Windows using: Clojure 1.8.0 and Java HotSpot(TM) 64-Bit Server VM 1.8.0_112-b15

I went ahead and tested it in regular Java and it works fine. So the class is installed on the system. Can anyone show me what I'm doing wrong here? Am I calling it incorrectly? Is there something else I need to import perhaps? Any advice is greatly appreciated.

1 Answer 1

5

This gives you trouble because Form is an inner class. In bytecode, a class outer.inner is actually represented as outer$inner. See more in this SO question, and this google group post.

(import java.text.Normalizer
        java.text.Normalizer$Form)
(java.text.Normalizer/normalize "Ἑλλάς" java.text.Normalizer$Form/NFD) ;; "Ἑλλάς"
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you so much! Yes, this works exactly as needed. Unfortunately, I didn't think to search for "static inner java class" after banging my head against this. But in any case, thank you for the quick and clear response!
Glad I could help! if this answered your question, you should accept the answer :)
Done. Thank you again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.