javapythoncastingtypingjcc

How to cast variables in python with jcc


In java it is possible to cast an object onto a class. An good example is found here

Object aSentenceObject = "This is just a regular sentence";
String aSentenceString = (String)aSentenceObject;

I have a program that needs to integrate some java with python. I am trying to do this via the JCC library. The problem that I am encountering is that with JCC, all of the java classes are loaded into the imported library that I created with JCC. So I can create an instance of the base class by passing the necessary argument to the constructor of the java class.

obj = javaLibrary.BaseClass('foo')

However, in my code I need to be able to cast this object onto a a more “specific” type of Object. How can I accomplish this in python with JCC? It seems like it may be impossible because python is dynamically typed, but that is why I am asking this question.


Solution

  • All comments above valid, but to be specific for your case:

    casted_obj = Object.cast_(obj)