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 184.108.40.206, 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?
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.
class RubyLabel < JLabel
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
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
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
Charlie, I think your comment of 8/25/08 indicates that it isn’t possible to
have different constructor arities, doesn’t it?
blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]