title: Jython: Instantiating java class in script as Java object, not as Python object
body: <p>I have a problem when using Jython, but I can't seem to find a solution in the documentation.</p>
  
  <p>Basically what I have is an object that has been instantiated in Java, and I want to instantiate another Java object (in the python script) and have the pre-instatiated java object added to the object I have instantiated in the jython interpreter.</p>
  
  <p>For example:</p>
  
  <pre><code>public class A {
      private B bInstance;
  
      public void setB(B bval) {
          bInstance = b;
      }
  }
  
  public class B {
      private String name;
  
      public String getName() {
          return name;
      }
  
      public void setName(String n) {
          this.name = n;
      }
  }
  </code></pre>
  
  <p>python script (there is an instance of B bound as "b_inst"):</p>
  
  <pre><code>import com.package.A
  a_inst = com.package.A()
  a_inst.setB(b_inst)
  </code></pre>
  
  <p>When I try to run the above code I get the following exception:
      TypeError: setB(): expected 2 args; got 1</p>
  
  <p>I am pretty sure this is because the setB() method is attempting to call a method on a Python object, not on the actual java object. Basically I expect the call to setB() on the instance of A I have just created in the jython script to be a java object, not a python object.</p>
  
  <p>Sorry if this is obvious, I've read the tutorials as well as the Jython sections of "Java in a Nutshell" and "Core Python Programming", but the examples are really really simple, they have no examples of how to do this two-way binding.</p>