Last active
December 11, 2020 02:49
-
-
Save slothbear/8961477 to your computer and use it in GitHub Desktop.
new_instance returns Java::JavaObject instead of a java.awt.Color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| constructor = java.awt.Color.java_class.constructor(Java::int, Java::int, Java::int) | |
| some_color = constructor.new_instance(134, 178, 25).getRGB | |
| # => Error: | |
| # NoMethodError: undefined method `getRGB' for #<Java::JavaObject:0x6386ec27> | |
| # solution: call to_java(java.awt.Color) | |
| other_color = constructor.new_instance(134, 178, 25).to_java(java.awt.Color).getRGB | |
| # OR: since new_instance returns a proxy, it still knows about its Color-ness: | |
| proxy_color = constructor.new_instance(134, 178, 25).to_java.getRGB | |
| # what | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment