Login  Register

Re: Problem with using Radio Buttons in a plugin when called from a macro

Posted by Stein Rørvik on Apr 17, 2019; 9:39pm
URL: http://imagej.273.s1.nabble.com/Problem-with-using-Radio-Buttons-in-a-plugin-when-called-from-a-macro-tp5022095p5022099.html

What baffled me was that in both cases the same compiled plugin yielded different results. How string comparison happens in the macro language is not relevant here as this happens inside the Java plugin code.

But your explanation sounds right. Since the plugin is compiled, the compiler probably assigns identical strings found in different parts of the code to one reused object to save heap space, so the comparison gets true because we are comparing the same object. When the plugin is called from the macro, the string being compared comes from the "outside" and is thus a different object, even if the value is the same. So using "equals" is the solution that will work in both cases.

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Kenneth Sloan
Sent: 17. april 2019 22:27
To: [hidden email]
Subject: Re: Problem with using Radio Buttons in a plugin when called from a macro

Probably because the macro language is not Java.  In Java, "==" tests for identity.  Two objects compare as "==" if and only if they are the SAME OBJECT.  Two strings that have the same contents are not the same string.

I'm not an expert in the macro language, but I suspect that in a macro "==" test for equal VALUES, so two distinct strings that happen to have the same sequence of characters are "==".

In Java, testing for equal values requires "equals".  Question: is there an "equals" in the macro language?

The question of "equality" vs "identity" is a tricky one.  Different languages answer it in different ways.

--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On Apr 17, 2019, at 14:11, Stein Rørvik <[hidden email]> wrote:
>
> Thanks, that works!
>
> But why the difference between running from the GUI and a macro?
> The comparison mycar=="Ford" works when the plugin is called via the GUI.
>
> Stein
 
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html