Skip to content

Commit 1ced829

Browse files
committed
document Java interop
1 parent 3d9b73c commit 1ced829

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

doc/INTEROP.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ def python_method():
4949
return "Hello from Python!"
5050
```
5151

52+
Finally, to interoperate with Java (only when running on the JVM), you can use
53+
the `java` module:
54+
```python
55+
import java
56+
BigInteger = java.type("java.math.BigInteger")
57+
myBigInt = BigInteger(42)
58+
myBigInt.shiftLeft(128) # public Java methods can just be called
59+
myBigInt["not"]() # Java method names that are keywords in
60+
# Python can be accessed using "[]"
61+
byteArray = myBigInt.toByteArray()
62+
print(list(byteArray)) # Java arrays can act like Python lists
63+
```
64+
5265
#### Python responses to Truffle interop messages
5366

5467
###### READ

0 commit comments

Comments
 (0)