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 4240820
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:13:05+00:00 2026-05-21T03:13:05+00:00

In my clojure program I cannot access package scoped fields of the java class

  • 0

In my clojure program I cannot access package scoped fields of the java class com.foo.Foo although I am in the namespace “com.foo” (via “(ns com.foo)” at the top of my clojure program). However, public fields in com.foo.Foo are accessible.

Why?

  • 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-21T03:13:06+00:00Added an answer on May 21, 2026 at 3:13 am

    Two problems here:

    First, the namespace com.foo is compiled to a class foo_whatever in package com; it’s not compiled to a class in package com.foo.

    See:

    user> (ns com.foo)
    nil
    com.foo> 
    nil
    com.foo> (defn hello[] "hello !")
    #'com.foo/hello
    com.foo> (class hello)
    com.foo$hello
    com.foo> (ns com.foo.hello)
    nil
    com.foo.hello> (defn hi[] "hi !")
    #'com.foo.hello/hi
    com.foo.hello> (class hi)
    com.foo.hello$hi
    

    Second, when looking for constructors or fields, the Clojure compiler uses methods getConstructor and getFields from java.lang.Class, which, by spec, only return the public constructors and public fields.

    So, bad luck here. It seems you won’t be able to access package-protected fields.

    Edit, answering comments. The best approach for accessing package-level fields in legacy Java code would be to write a class in Java that wraps the existing class and which exposes the package protected methods and fields from that class with public methods. This way, you have more control over the name and package of the generated class.

    This wrapper is a small amount of Java code, and from there you can access the fields from Clojure code.

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

Sidebar

Related Questions

Begin Edit: Primarily I want my Clojure program to use a Java class. I've
Can I use other JVM languages besides Java (e.g. jruby, jython, clojure) to program
I'd like to wrap java's PriorityQueue class in clojure for use in another part
I have a dummy Java Program, which I want to write in Clojure. It
Consider the following: using System; using System.Dynamic; namespace DynamicTest { class Program { static
This is a clojure program to read integers from a file and count the
Clojure structs can be arbitrarily extended, adding new fields. Is it possible to extend
What would cause a Clojure program to not immediately exit upon finishing the last
How can a Clojure program find its own MANIFEST.MF (assuming it is packaged in
After a few weekends exploring Clojure I came up with this program. It allows

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.