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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:37:44+00:00 2026-05-11T16:37:44+00:00

I wonder if it possible to not have jython automagicaly transform java objects to

  • 0

I wonder if it possible to not have jython automagicaly transform java objects to python types when you put them in a Java ArrayList.

Example copied from a jython-console:

>>> b = java.lang.Boolean("True");
>>> type(b)
<type 'javainstance'>
>>> isinstance(b, java.lang.Boolean);
1

So far, everything is fine but if I put the object in an ArrayList

>>> l = java.util.ArrayList();
>>> l.add(b)
1
>>> type(l.get(0))
<type 'int'>

the object is transformed into a python-like boolean (i.e. an int) and…

>>> isinstance(l.get(0), java.lang.Boolean)
0

which means that I can no longer see that this was once a java.lang.Boolean.

Clarification

I guess what really want to achieve is to get rid of the implicit conversion from Java-types to Python-types when passing objects from Java to Python. I will give another example for clarification.

A Python module:

import java

import IPythonModule

class PythonModule(IPythonModule):

    def method(self, data):
        print type(data);

And a Java-Class that uses this module:

import java.util.ArrayList;

import org.python.core.PyList;
import org.testng.annotations.*;

import static org.testng.AssertJUnit.*;

public class Test1 {

    IPythonModule m;

    @BeforeClass
    public void setUp() {
        JythonFactory jf = JythonFactory.getInstance();
        m = (IPythonModule) jf.getJythonObject(
                "IPythonModule",
        "/Users/sg/workspace/JythonTests/src/PythonModule.py");
    }

    @Test
    public void testFirst() {
        m.method(new Boolean("true"));
    }   
}

Here I will see the output ‘bool’ because of the implicit conversion, but what I would really like is to see ‘javainstance’ or ‘java.lang.Boolean’. If you want to run this code you will also need the JythonFactory-class that can be found here.

  • 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-11T16:37:44+00:00Added an answer on May 11, 2026 at 4:37 pm

    You appear to be using an old version of Jython. In current Jython versions, the Python bool type corresponds to a Java Boolean.

    Jython is not transforming the Java type to a Python type on the way into the ArrayList – on the contrary, it will transform a primitive Python type to a primitive or wrapper Java type when passing it to a Java method, and a Java type to a Python type on the way out.

    You can observe this by printing the contents of the array. Note that the Python bool is capitalized (True); the Java Boolean is not.

    >>> from java.lang import Boolean
    >>> b = Boolean('True')
    >>> b      
    true
    >>> from java.util import ArrayList
    >>> l = ArrayList()
    >>> l.add(b)
    True
    >>> l
    [true]
    >>> l.add(True)
    True
    >>> l
    [true, true]
    >>> list(l) 
    [True, True]
    

    If this still doesn’t do what you want, consider writing a small Java helper function that examines the array for you without conversion. It’s arguably a bug that Jython doesn’t automatically convert the Boolean you constructed into a Python bool, and in this case it gives you no advantage over using Boolean.TRUE or the Python True.

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

Sidebar

Ask A Question

Stats

  • Questions 153k
  • Answers 153k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Don't use the repository pattern - use the UnitOfWork pattern… May 12, 2026 at 10:18 am
  • Editorial Team
    Editorial Team added an answer Objective C is essentially C with extra stuff on top.… May 12, 2026 at 10:18 am
  • Editorial Team
    Editorial Team added an answer Sounds like your directory needs the write permissions as well. May 12, 2026 at 10:18 am

Related Questions

Okay, weird situation: I need to Debug a VSTO Office Addin. This was written
I just wonder if it is possible to only use CSS but not javascript
Not all that familiar with XSD, I wonder if it is possible to do
I wonder if it's possible to keep methods for a Python class in a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.