Skip to content

Commit 5944a0a

Browse files
committed
Update host interop docs
1 parent e16a0c2 commit 5944a0a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

doc/user/jruby-migration.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,28 +327,31 @@ require 'java'
327327
# With the 'require' above, you now can refer to things that are part of the
328328
# standard Java platform via their full paths.
329329
frame = javax.swing.JFrame.new("Window") # Creating a Java JFrame
330-
label = javax.swing.JLabel.new("Hello")
330+
label = javax.swing.JLabel.new("Hello World")
331331

332332
# You can transparently call Java methods on Java objects, just as if they were defined in Ruby.
333333
frame.add(label) # Invoking the Java method 'add'.
334-
frame.setDefaultCloseOperation(javax.swing.JFrame::EXIT_ON_CLOSE)
334+
frame.setDefaultCloseOperation(javax.swing.WindowConstants::EXIT_ON_CLOSE)
335335
frame.pack
336336
frame.setVisible(true)
337+
sleep
337338
```
338339

339340
In TruffleRuby we would write that this way instead:
340341

341342
```ruby
342343
Java.import 'javax.swing.JFrame'
343344
Java.import 'javax.swing.JLabel'
345+
Java.import 'javax.swing.WindowConstants'
344346

345347
frame = JFrame.new("Window")
346-
label = JLabel.new("Hello")
348+
label = JLabel.new("Hello World")
347349

348350
frame.add(label)
349-
frame.setDefaultCloseOperation(JFrame[:EXIT_ON_CLOSE])
351+
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE)
350352
frame.pack
351353
frame.setVisible(true)
354+
sleep
352355
```
353356

354357
Instead of using Ruby metaprogramming to simulate a Java package name, we explicitly import classes.
@@ -383,8 +386,7 @@ TruffleRuby does not perform these conversions.
383386
### Referring to Constants
384387

385388
In JRuby, Java constants are modelled as Ruby constants, `MyClass::FOO`.
386-
In TruffleRuby you use the read notation to read them as a property,
387-
`MyClass[:FOO]`.
389+
In TruffleRuby you use the read notation to read them as a property, `MyClass.FOO` or `MyClass[:FOO]`.
388390

389391
### Using Classes from JAR files
390392

doc/user/polyglot.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ It is easier to use Java interoperability in JVM mode (`--jvm`). Java interopera
151151
See [here](https://github.com/oracle/graal/blob/master/docs/reference-manual/embedding/embed-languages.md#build-native-images-from-polyglot-applications) for more details.
152152

153153
`Java.type('name')` returns a Java type, given a name such as `java.lang.Integer` or `int[]`.
154-
With the type object, `.new` will create an instance, `.foo` will call the static method `foo`, `[:FOO]` will read the static field
155-
`FOO`, and so on.
154+
With the type object, `.new` will create an instance, `.foo` will call the static method `foo`, `.FOO` or `[:FOO]` will read the static field `FOO`, and so on.
156155
To access methods of the `java.lang.Class` instance, use `[:class]`, such as `MyClass[:class].getName`.
157156
You can also go from the `java.lang.Class` instance to the Java type by using `[:static]`.
158157

0 commit comments

Comments
 (0)