Forum: JRuby Fwd: Import/Include Static Java Methods

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

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.

Cheers,

António Alegria
This topic is locked and can not be replied to.