Skip to content

Commit

Permalink
Examples of multi-dimensional jarray.array and Java object element ty…
Browse files Browse the repository at this point in the history
…pe (bjo2758). (#5)

This change answers the perceived lack of multi-dimensional arrays in Jython identified first as bjo2758, through richer examples in the relevant chapter.
  • Loading branch information
adamburkegh authored and jeff5 committed Jun 12, 2019
1 parent 9c4aa83 commit 2ddb05b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions chapter2.rst
Expand Up @@ -842,6 +842,25 @@ Table 2-8. Character Typecodes for use with Jarray ::
>>> array(myStr,'c')
array('c', 'Hello Jython')

Java arrays can be constructed of arbitrary Java classes using jarray, if needed.

>>> from java.lang import StackTraceElement
>>> array([],StackTraceElement)
array(java.lang.StackTraceElement)

As arrays in Java always have an associated class, this also allows working with two-dimensional or higher-dimensional arrays.

>>> from java.lang import Class
>>> intArrayClass = Class.forName('[I') # Name of an array of Java int
>>> a = array([[1,2,3],[6,7,8,9]],intArrayClass)
>>> a[1][3]
9


The names for primitive arrays can be found in the Java documentation for the *Class.getName()* method.



Files
-----

Expand Down

0 comments on commit 2ddb05b

Please sign in to comment.