Created
November 17, 2013 19:55
-
-
Save daicoden/7517481 to your computer and use it in GitHub Desktop.
Just some ideas for a couple more things I have run into
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
java_import com.foo.MyJavaClass | |
java_import com.foo.MyJavaInterface | |
java_import com.foo.TemplateClass | |
# Extending from generic superclass | |
# This is needed because a new type is created, and | |
# there is no way currently in JRuby to specify template classes | |
# because most template information is unavailable during runtime | |
class MyRuby < MyJavaClass(TemplateClass) | |
end | |
# Implementing a generic interface | |
class AnotherRuby | |
include MyJavaInterface(TemplaceClass) | |
end | |
# Creating a Java Interface in Ruby | |
# This will allow Ruby to interface with libraries | |
# like Guice in use cases where it requires an interface | |
# instead of a class | |
# The idea is just treat modules as straight up interfaces and add become_java! to it. | |
module RubyInterface | |
add_interface_annotations(com.foo.Interface => {"value" => "bar"}) | |
def foo | |
puts "HI" | |
end | |
add_method_annotation(:foo, com.foo.FunctionInterface => {"value" => "zot"}) | |
become_java! false | |
end | |
# This would work by generating java bytecode which was just the interface, | |
# but we would create a proxy module which contained the | |
# implementation that ruby would be able to include |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment