Forum: JRuby Fwd: Import/Include Static Java Methods

7caea854a8b74b6fd1161ddaa4ece877?d=identicon&s=25 "António Alegria" <> (Guest)
on 2012-07-10 10:47
(Received via mailing list)

I am trying to include all static methods in a Java class so that
instead of calling Math.atan(1) I can just call atan(1).

To achieve this in Java I would do:

import static java.util.Math.*; // or java.util.Math.atan;

In JRuby I found out this isn't possible. E.g:

include_package 'java.util.Math' # or 'java.util.Math.*'

atan(1)          # => ERROR: atan not found
Math.atan(1) # => OK

# Alternative
m = Math
m.atan(1) # => ok, and best solution so far.

It would be greatly appreciated if we could include all/some static
methods in a Module to be called without the class name.


António Alegria
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.