2

How does one go about importing a Java class located inside another Java class from Clojure?

The class I am attempting to import is the Pixmap.Format located in the LibGDX library. As play-clj handles the integration with LibGDX for Clojure, there is no problem whatsoever actually importing classes from LibGDX itself. The problem lies in importing the Format class located inside the Pixmap class.

I have tried a couple of different things:

; This I have tried
(ns pfft.test 
    (:import com.badlogic.gdx.graphics Pixmap.Format))

; And this
(ns pfft.test 
    (:import com.badlogic.gdx.graphics Pixmap/Format))

; This
(ns pfft.test 
    (:import com.badlogic.gdx.graphics.Pixmap.Format))

I have also attempted calling the class like this:

(Pixmap/Format/RGBA8888)

But Clojure tells me there is no such field, which there clearly is.

This too, does not work:

((Pixmap/Format)/RGBA8888)

As the...

/RGBA8888

... is not recognized at all.

0

1 Answer 1

6

The separator you're looking for is $, so you can import the nested class like this:

(import com.badlogic.gdx.graphics.Pixmap$Format)

Or like this:

(import (com.badlogic.gdx.graphics Pixmap$Format))

Then you can access static fields of Pixmap$Format like this:

Pixmap$Format/RGBA8888

See this Stack Overflow question and this part of the Clojure docs for more information.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.