http://jira.codehaus.org/browse/JRUBY-2457 Not Resolved?

All -

A few years ago I reported an issue, which eventually became bug #2457
(Instantiation of Ruby subclass of Java class does incorrect constructor
argument check, http://jira.codehaus.org/browse/JRUBY-2457).

It was marked resolved, but I’m still having the same problem. I’m using
JRuby 1.6.7.2, but I don’t think it’s version-specific.

I’ve posted a gist illustrating it:

Charlie, I think your comment of 8/25/08 indicates that it isn’t
possible to have different constructor arities, doesn’t it?

Thanks,
Keith

All -

I was wrong about this – this is not an error, and the gist I provided
was not relevant, as it illustrated the implementation of an interface
and not a subclass. Sorry about that.

I did actually have a problem subclassing a Java class with no
arguments, but it was due to my misunderstanding. What confused me was
that I thought it was always true that a function call with no arguments
never needs parentheses; that is, that “foo” and “foo()” were
interchangeable. This is not true with super, since without the parens
it will assume that it’s passing the same arguments that were passed to
it (I think…is this correct?). It didn’t occur to me until much
later (um, today) to try super(). So super is a special case.

The example below illustrates it.


require ‘java’

java_import ‘javax.swing.JLabel’

class RubyLabel < JLabel
def initialize(a,b,c,d,e,f)

super # doesn’t work; passes all arguments

super() # does work; passes no arguments

super(‘text’) # does work; one of superclass JLabel’s ctor’s takes

a string arg

# omitting super behaves as if it were called without

parens
end
end

RubyLabel.new(1,2,3,4,5,6)

  • Keith

Yeah I think super without args (known as zsuper) is a horrific
feature of Ruby because every single programmer who first encounters
zsuper gets confused by the magicness of it. Once you hit it once you
never forget it though :slight_smile:

-Tom

On Thu, Aug 23, 2012 at 10:15 PM, Keith B.
[email protected] wrote:

not true with super, since without the parens it will assume that it’s

All -
https://gist.github.com/3390231

Charlie, I think your comment of 8/25/08 indicates that it isn’t possible to
have different constructor arities, doesn’t it?

Thanks,
Keith


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs