Skip to content

Instantly share code, notes, and snippets.

@daicoden
Created November 17, 2013 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daicoden/7517481 to your computer and use it in GitHub Desktop.
Save daicoden/7517481 to your computer and use it in GitHub Desktop.
Just some ideas for a couple more things I have run into
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