Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

6. Using Java from Jython > Basic Object Usage

Basic Object Usage

In Importing Java Classes in Chapter 4, we showed how you can retrieve Java classes using the import statement. The Jython runtime wraps both Java classes and instances inside proxy objects, which offer a natural and intuitive mix between what you expect from Java semantics and what you have learned so far about user-defined Python classes. Using these objects, Jython provides a number of automatic conversions when passing objects back and forth between Jython and Java code.

When using a Java class in Jython, you can, by default, access all inner classes, static fields, static methods, and instance methods—as long as they are defined as public. If you need to get access to protected or private members, you can set the Jython registry option python.security.respectJavaAccessibility = false, an option used mainly for testing. The following code shows how you can import and then use Java classes and methods from the interpreter:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint