Forum: JRuby Fwd: Import/Include Static Java Methods

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
"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
This topic is locked and can not be replied to.