You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This global should then work as expected; accessing attributes assumes it reads
54
+
from the `members` namespace; accessing items is supported both with strings and
55
+
numbers; calling methods on the result tries to do a straight invoke and falls
56
+
back to reading the member and trying to execute it.
57
+
58
+
59
+
## Examples
54
60
Here is an example of how to use JavaScript regular expression engine to
55
61
match Python strings. Save this code to the `polyglot_example.py` file:
56
62
@@ -135,7 +141,7 @@ the `java` module:
135
141
```python
136
142
import java
137
143
BigInteger = java.type("java.math.BigInteger")
138
-
myBigInt = BigInteger(42)
144
+
myBigInt = BigInteger.valueOf(42)
139
145
myBigInt.shiftLeft(128) # public Java methods can just be called
140
146
myBigInt["not"]() # Java method names that are keywords in
141
147
# Python can be accessed using "[]"
@@ -144,7 +150,8 @@ print(list(byteArray)) # Java arrays can act like Python lists
144
150
```
145
151
146
152
For packages under the `java` package, you can also use the normal Python import
147
-
syntax:
153
+
syntax. This syntax is limited to importing concrete classes, it doesn't work
154
+
on packages, unless in [Jython Compatibility](Jython.md) mode.
148
155
```python
149
156
import java.util.ArrayList
150
157
from java.util import ArrayList
@@ -179,5 +186,5 @@ print(java.is_function(my_list.add))# prints True, the add method of ArrayList
179
186
print(java.instanceof(my_list, ArrayList)) # prints True
180
187
```
181
188
182
-
See the [Polyglot Programming](https://www.graalvm.org/docs/reference-manual/polyglot-programming/) and the [Embed Languages](https://www.graalvm.org/reference-manual/embed-languages/) reference
189
+
See the [Polyglot Programming](https://www.graalvm.org/reference-manual/polyglot-programming/) and the [Embed Languages](https://www.graalvm.org/reference-manual/embed-languages/) reference
183
190
for more information about interoperability with other programming languages.
0 commit comments