Hello all.
Noticed this today:
require ‘java’
textArea = javax.swing.JTextArea.new
textArea.preferred_size
=> niltextArea.getPreferredSize
=> java.awt.Dimension[width=0,height=16]
Shouldn’t these two methods be the same?
Thanks.
-roger-
Hello all.
Noticed this today:
require ‘java’
textArea = javax.swing.JTextArea.new
textArea.preferred_size
=> niltextArea.getPreferredSize
=> java.awt.Dimension[width=0,height=16]
Shouldn’t these two methods be the same?
Thanks.
-roger-
Good question. Component does in fact have a mangy old
preferredSize() method on it. That short cut probably points at that
instead of getPreferredSize().
-Tom
On Tue, Jun 19, 2012 at 12:44 PM, Roger P. [email protected]
wrote:
–
blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]
yikes. That method should have been deprecated and removed years ago if
it doesn’t even call out to getPreferredSize.
But that probably explains it. Thanks!
-r
On Tue, Jun 19, 2012 at 12:48 PM, Thomas E Enebo [email protected]
wrote:
Good question. Component does in fact have a mangy old
preferredSize() method on it. That short cut probably points at that
instead of getPreferredSize().-Tom
Can we anticipate a change to the effect of JRuby always trying the
get* version first? I would imagine that sort of error would take a
long time to track down; and maybe it’s just me, but when that sort of
thing bites me a few times, I start being extra defensive, e.g. adding
get_ in the 99% of cases where it’s not necessary.
On Tue, Jun 19, 2012 at 7:40 PM, Eric C.
[email protected] wrote:
Can we anticipate a change to the effect of JRuby always trying the
get* version first? I would imagine that sort of error would take a
long time to track down; and maybe it’s just me, but when that sort of
thing bites me a few times, I start being extra defensive, e.g. adding
get_ in the 99% of cases where it’s not necessary.
The problem with that is all the other cases where you do want the
non-get method to be bound to the shortcut name. It’s not a good
practice in API design to mix both bean-style and “bare” getters like
this, but it does happen.
Our policy has always been this:
At each stage, we only bind the name if it has not already been bound,
so preferredSize wins preferred_size because it’s the earliest,
simplest alias.
Probably just have to chalk this up to a bad API in Java. Our aliasing
is done mostly as a convenience and it usually works fine. Using get_
defensively isn’t a bad idea, but it’s only necessary in cases like
this.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs