Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:02:05+00:00 2026-05-23T12:02:05+00:00

For the purposes of interoperability with Java, I need a class that has a

  • 0

For the purposes of interoperability with Java, I need a class that has a nullary constructor that performs initialization.
Objects of this class need to have something resembling mutable java fields (namely, the object represents the backend of a game, and needs to keep game state).

deftype does everything I want to do except provide a nullary constructor (since I’m creating a class with fields).

I don’t need the fields to be publicly readable, so I can think of 4 solutions:

Use gen-class; I don’t want to do this if I can avoid it.
Somehow encoding private member variables outside of the knowledge of deftype; I’ve been told this can’t be done.
Writing a modified deftype that also creates a nullary constructor; frankly I don’t know clojure well enough for this.
Taking the class created by deftype and somehow adding a new constructor to it.

At the end of this, I need to have a Java class, since I will be handing it off to Java code that will be making a new object from the class.

Are any of the solutions I suggested (or any that I haven’t thought of) other than using gen-class viable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:02:06+00:00Added an answer on May 23, 2026 at 12:02 pm

    There’s absolutely no shame in, where appropriate, writing a dash of Java if your Java interop requirements are simultaneously specific and unshakable. You could write a Java class with a single static factory method that returns an instance of the deftype class and that does whatever initialization/setup you need.

    Alternatively, you can write a nullary factory function in Clojure, and call that directly from Java all day long.

    In any case, neither deftype nor defrecord are intended to be (or will they ever be) fully-featured interop facilities. gen-class certainly comes the closest, which is why it’s been recommended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For custom rendering purposes, I've created a class (axialPanel.java) that extends JPanel and overrides
For the purposes of this question, the code base is an ASP.NET website that
for testing purposes i need an recursive directory with some files, that comes to
For debugging purposes I would like to have a printf_debug function that would function
for designing purposes i need to truncate all DB which has lots of FK's.
For testing purposes, I need to find two 64-bit integer values that exactly multiply
For debugging purposes, I need to configure Java to use a proxy for HTTP
For debugging purposes I need to print all public fields/properties of certain class instance.
For testing purposes I need a function like this: /** * @param int $sizeInBytes
For debugging purposes in a somewhat closed system, I have to output text to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.