Re: java static field considered as a function instead of boolean in jython (unexpected behaviour / bug ?)
Jeff Emanuel <jemanuel <at> frii.com>
2009-02-04 18:15:02 GMT
Tim,
I figured there was something like that.
Since your isWindows field is not public,
it won't (by default) be accessible from Jython,
so you'll only see the isWindows method.
To call the isWindows method you need
parentheses:
>>> import Test
>>> Test.isWindows()
1
Third, if the static field is declared public
(or your accessiblity settings allow it) so
that you have a true name collision, Jython's
precedence hides the field (at least through 2.2.1).
However, you can still access the field with Java
reflection.
>>> Test.getDeclaredField('isWindows').get(None)
1
I hope that helps.
Jeff
Tim Van den Bulcke wrote:
> Hi Jeff,
>
> thank you for your reply. I had oversimplified the problem in the post:
> there needed to be an additional method in the Test class which was also
> called isWindows().
>
> For completeness, this is what the code should have looked like in my
> previous post:
> public class Test {
> static boolean isWindows = System.getProperty("os.name
> ").toLowerCase().contains("windows");
>
> /* ... */
>
> public static final boolean isWindows() {
> return isWindows;
> }
> }
>
> In Java there is no confusion possible between the isWindows field and the
> isWindows() function. However in jython the field gets hidden by the
> function.
>
>
> My problem is solved now (my apologies for the incomplete previous post) but
> leads to a perhaps equally interesting question: if such Test class like the
> above one is given, is it then possible to access both the function
> "isWindows()" and the field "isWindows" of the Test class from within
> jython?
>
>
> Thanks,
>
> Tim.
>
>
>
> On Wed, Feb 4, 2009 at 5:39 PM, Jeff Emanuel <jemanuel <at> frii.com> wrote:
>
>
>> It works for correctly me on Jython 2.2.1 and Java 1.6.
>> I made the isWindows field public. Otherwise, I get
>> AttributeError: class 'Test' has no attribute 'isWindows'
>>
>> Jython 2.2.1 on java1.6.0_04
>> Type "copyright", "credits" or "license" for more information.
>>
>>>>> import Test
>>>>> Test.isWindows
>>>>>
>> 1
>>
>>
>>
>> Tim Van den Bulcke wrote:
>>
>>
>>> Hi,
>>>
>>> I have the following java class with one static boolean field "isWindows":
>>>
>>> public class Test {
>>> static boolean isWindows = System.getProperty("os.name
>>> ").toLowerCase().contains("windows");
>>> }
>>>
>>> After compiling this class and launching the jython interactive console,
>>> this is the output when asking for the content of the field "isWindows":
>>>
>>>
>>>
>>>
>>>> Test.isWindows
>>>>
>>>>>>>
>>>>>> <java function isWindows 1>
>>>>>>
>>> I would expect a boolean with value "True" on my Windows machine, but
>>> instead I get a handle to a java function. If "Test.isWindows" is called
>>> from within java, a boolean is returned as expected. Is this normal jython
>>> behaviour or not? And if so, why?
>>>
>>> For completeness:
>>> - I am running Jython version 2.2a1 and Java 1.5 runtime
>>> - System.getProperty("os.name") results in "Windows XP" on my machine
>>>
>>>
>>> Thanks in advance for any feedback,
>>>
>>> Tim.
>>>
>>> ------------------------------------------------------------------------
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Create and Deploy Rich Internet Apps outside the browser with
>>> Adobe(R)AIR(TM)
>>> software. With Adobe AIR, Ajax developers can use existing skills and code
>>> to
>>> build responsive, highly engaging applications that combine the power of
>>> local
>>> resources and data with the reach of the web. Download the Adobe AIR SDK
>>> and
>>> Ajax docs to start building applications today-
>>> http://p.sf.net/sfu/adobe-com
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Jython-users mailing list
>>> Jython-users <at> lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jython-users
>>>
>>>
>>>
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code to
> build responsive, highly engaging applications that combine the power of local
> resources and data with the reach of the web. Download the Adobe AIR SDK and
> Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
> ------------------------------------------------------------------------
>
> _______________________________________________
> Jython-users mailing list
> Jython-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com