gen-class automatically generates Java classes from Clojure code.
Questions tagged [gen-class]
36 questions
8
votes
2 answers
clojure gen-class varargs constructor
in the :constructors map and subsequent -init definitions, how do I represent a varargs constructor (assuming the superclass has multiple constructors of which one is varargs) ?

Hendekagon
- 4,565
- 2
- 28
- 43
8
votes
1 answer
Clojure multiple constructors using gen-class
How can i define multiple constructors and states using gen-class in clojure?
I do not see a way to do this with single valued mappings for :init, :state and :constructors.

FUD
- 5,114
- 7
- 39
- 61
7
votes
1 answer
Clojure gen-class for overloaded and overridden methods
I'm trying to use gen-class to override the compare(WriteableComparable a, WriteableComparable b) method in this class in clojure. The complication comes from the fact that this method is overloaded 3 times:
int compare(WritableComparable a,…

dsg
- 12,924
- 21
- 67
- 111
6
votes
3 answers
Attaching metadata to a Clojure gen-class
Is it possible to attach metadata to a Clojure gen-class?
I am trying to implement a server that uses a library that requires Java annotations added to classes.
From Chas Emerick's, et al., forthcoming book "Programming Clojure" (section 9.7.3),…

Ralph
- 31,584
- 38
- 145
- 282
6
votes
3 answers
How to compile Java code after Clojure code in leiningen
In my Leiningen project:
(defproject com.stackoverflow.clojure/tests "0.1.0-SNAPSHOT"
:description "Tests of Clojure test-framework."
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url…

Edward
- 4,453
- 8
- 44
- 82
5
votes
1 answer
Why can't Leiningen always use my :gen-class properly?
Let's say I create a new Leiningen project (lein new app example) and add some code in example/src/example/core.clj that makes use of :gen-class:
(ns example.core
(:gen-class :extends javafx.application.Application))
(defn -start [this stage]
…

Sam Estep
- 12,974
- 2
- 37
- 75
5
votes
1 answer
How to generate generate static methods with clojure's Gen-class?
In My Clojure-code I'd like to generate a class-file that contains a static method (named staticMethod), which is later on called by in a static context from a Java-program.
I tried (Clojure):
(ns com.stackoverflow.clojure.testGenClass
…

Edward
- 4,453
- 8
- 44
- 82
5
votes
1 answer
Can gen-class override a protected Java method?
I'm trying to use Swing from Clojure, and I'm getting confused by gen-class and I can't tell from the documentation if this is supposed to work - paintComponent is a protected method on JPanel, and I'm able to override it, but when I try to call the…

jes5199
- 18,324
- 12
- 36
- 40
5
votes
1 answer
clojure macro using gen-class doesn't create annotations
I'm trying to write a clojure macro that will be used to generate multiple Java classes at compile time. I've found that I can add annotations to a class when I invoke gen-class outside of a macro. However, when I try to use gen-class inside a…

Michael Willis
- 101
- 7
4
votes
1 answer
gen-class not generating a class
I'm having difficulty referencing classes generated via :gen-class.
The smallest example I can show that demonstrates the problem is:
(defproject test-proj
:dependencies [[org.clojure/clojure "1.8.0"]]
:aot [test-proj.test])
(ns…

Carcigenicate
- 43,494
- 9
- 68
- 117
4
votes
1 answer
Problem Extending A Class in Clojure: ClassFormatError: Duplicate field name&signature
I'm trying to extend JButton with Clojure, but I ran into a problem when I try to create my own constructors. Whenever I use :constructors with :gen-class I keep getting a "ClassFormatError: Duplicate field name&signature" message when I try to…

Cristian
- 42,563
- 25
- 88
- 99
4
votes
2 answers
What is wrong with my simple Clojure gen-class script?
I'm trying to learn how to use gen-class in Clojure. I've started with this simple script:
(gen-class :name MyClass :prefix MyClass-)
(defn MyClass-toString[this] "This Is My Class")
(println (MyClass.))
When I try to run it I get
Exception…

Idan Arye
- 12,402
- 5
- 49
- 68
4
votes
1 answer
How can a static initializer be defined using gen-class
I am generating a Java class from Clojure that implements a JDBC Driver, the problem is that usually JDBC drivers register themselves with the DriverManager in a static initializer like so:
public class MyDriver implements java.sql.Driver {
...
…

user1181316
- 119
- 4
4
votes
3 answers
Trouble understanding :state in Clojure
I understand what :state /does/. It creates a field, like in Java, in your class. What I don't understand is what is the point of this? It seems like I only see it done with Clojure-generated classes that extend other classes.…

Rayne
- 31,473
- 17
- 86
- 101
3
votes
2 answers
ClassCastException when returning LazySeq from Clojure to Java
I have Clojure function that returns a LazySeq. When I run this function from the REPL, it works just fine. However, if I try to call the same function from Java code like this:
Object result = com.acme.forecast.core.runforecast("file1.csv",…

Paul Reiners
- 8,576
- 33
- 117
- 202