Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access static method from a instance, error : NoMethodError (undefined method `currentThread' for #<Java::JavaLang::Thread:0x8f2fcd8>) #4113

Closed
javalovercn opened this issue Aug 25, 2016 · 2 comments

Comments

@javalovercn
Copy link

Environment

  • JRuby 1.7.3 all in one
  • Mac OS X, JRE 1.7

Expected Behavior

In Java, a instance can access a static method, just like a instance method,
but in JRuby, it raise this exception,

JRuby scripts as following :
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

encoding:utf-8

import Java::java.lang.Thread

t = Thread.new()
t.currentThread()
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

the exception is following :
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Caused by: org.jruby.embed.EvalFailedException: (NoMethodError) undefined method currentThread' for #<Java::JavaLang::Thread:0x8f2fcd8> at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:133) ... 11 more Caused by: org.jruby.exceptions.RaiseException: (NoMethodError) undefined methodcurrentThread' for #Java::JavaLang::Thread:0x8f2fcd8
at $lt_script_gt.(root)(<script>:6)
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

@kares
Copy link
Member

kares commented Aug 25, 2016

this is more of a feature instead of a bug - static Java methods get bind at class level (just like in proper Ruby land) thus do: t.class.currentThread or Thread.current_thread

@kares kares closed this as completed Aug 25, 2016
@kares kares added this to the Won't Fix milestone Aug 25, 2016
@javalovercn
Copy link
Author

thank very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants