Questions tagged [gen-class]

gen-class automatically generates Java classes from Clojure code.

36 questions
3
votes
2 answers

Extending with :gen-class a class that exposes its naked fields

Suppose there is a Java class that doesn't provide getters and setters for all its fields, and I have to extend it with :gen-class and fiddle with them. How do I access the superclass fields? The quickest (and perhaps cleanest...) solution that…
Rick77
  • 3,121
  • 25
  • 43
3
votes
0 answers

Lein install/uberjar fails when trying to use a class from dependency with gen-class

Getting ClassNotFoundException when i use a class from second order dependency. when i run lein uberjar or install it fails with java.lang.ClassNotFoundException: incanter.core.Dataset, compiling:(myproject/routes/evaluate.clj:1:1). However, it…
NehaM
  • 1,272
  • 1
  • 18
  • 32
3
votes
2 answers

Clojure's :gen-class and double arrays

I am attempting to :gen-class a fn which takes a 2D array of Doubles as input. I have already seen the post and solution here concerning a similar topic, but I am still unable to produce a working solution. (ns gui.heatmap (:gen-class :name…
cryptic_star
  • 1,863
  • 3
  • 26
  • 47
2
votes
2 answers

Creating an Android Service in Clojure

I have a fairly simple app, which I wrote in Clojure and would like to automatically execute one of it's functions periodically. I am trying to use Android's AlarmManager to schedule the task. This is what I have so far: Android's Documentation…
Adam Lee
  • 1,784
  • 1
  • 11
  • 15
2
votes
1 answer

Is it possible to gen-class with a private final field?

How to create a Java class with a private final field in Clojure? ClojureDocs for gen-class say that state field will be public :state name If supplied, a public final instance field with the given name will be created. So, in other words, do we…
Aleksei Sotnikov
  • 633
  • 4
  • 15
2
votes
1 answer

Clojure gen-class this keyword

Is it possible to refer to Java's 'this' keyword from within a gen-class method? I am trying to implement daredesm's answer here, in Clojure. However, when I try to use 'this' in the run function, I get "java.lang.RuntimeException: Unable to resolve…
Porthos3
  • 381
  • 5
  • 19
2
votes
1 answer

Clojure.org documentation on compilation and gen-class

I am reading the documention on clojure.org about compilation, the last part gen-class examples. I do the examples and then when trying to run it as java app with: java -cp ./classes:clojure.jar clojure.examples.hello Fred in the terminal i get :…
user4813927
2
votes
2 answers

Does Clojure inlines primitive operations efficiently?

Assuming I have the following Clojure code: (defn foo ^double [] (- (* 123.31 (+ 4 5 6 (Math/sin 34.2)) 123.31) 123)) Will gen-class produce byte code equivalent to compiling the following java code: public static double…
Lambder
  • 2,953
  • 1
  • 26
  • 20
2
votes
2 answers

Clojure -- how to define public mutable members using deftype?

I've been trying to get http://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm running in clojure. I discovered that by omitting the @FXML annotation in the java version and making things public, from: public class FXMLExampleController { …
Sonicsmooth
  • 2,673
  • 2
  • 22
  • 35
2
votes
1 answer

Is it possible to use clojure's gen-class macro to generate a class with static fields?

Can the following class be generated using Clojure's gen-class macro? public class Test { public static final String TEST_NAME = "This test's name."; } If not, why not?
2
votes
1 answer

How to generate a serializable java class in Clojure by gen-class?

We need to serialize a bunch of Java objects generated by Clojure into a file by Java Serialization mechanism. (gen-class :name lancelot.Instance :extends cc.mallet.types.Instance) (gen-class :name lancelot.FilterPipe :extends…
Mountain
  • 211
  • 3
  • 11
2
votes
1 answer

How to get a "class" out of proxy?

I want to generate a class (not an object) via proxy, and the class will be instantiated later. The examples I have found of Clojure's proxy method seem to largely deal with the most common java inner class scenario, i.e., when we are only defining…
jayunit100
  • 17,388
  • 22
  • 92
  • 167
1
vote
1 answer

How can I define in clojure a java class during runtime and instantiate it

I have tried to use gen-and-load-class from clojure.core and then use custom class loader to call defineClass with generated bytecode, but when I call (foo.bar.MyClass.) I'm getting CompilerExceptionjava.lang.NoClassDefFoundError: Could not…
Lambder
  • 2,953
  • 1
  • 26
  • 20
1
vote
0 answers

Clojure: How to create a Java Object at Compile time, but not Load Time or Run Time

I'm using a java library with Clojure. The java library requires an object to be created at compile-time only. When the app is deployed via an uberjar (created with leiningen), this configuration object cannot be created properly without an error. I…
1
vote
1 answer

clojure gen-class generated classes invocation issue

I defined the following MyCache.clj (ns abcd.MyCache (:gen-class :name "abcd.MyCache" :init "init" :constructors { [java.text.DateFormat][] } :methods [ [now [] void] [myformat [long] String] ] :state "state" :main false)) (defn…
psaradhi
  • 186
  • 1
  • 1
  • 8