octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #39074] java_get deprecated ok?


From: Rik
Subject: [Octave-bug-tracker] [bug #39074] java_get deprecated ok?
Date: Wed, 17 Jul 2013 22:38:22 +0000
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0

Update of bug #39074 (project octave):

             Open/Closed:                    Open => Closed                 

    _______________________________________________________

Follow-up Comment #2:

See the Mathworks Documentation on this subject
(http://www.mathworks.com/help/matlab/matlab_external/creating-and-using-java-objects.html?nocookie=true#f56755).

In particular, this boxed comment

Note:   MATLAB does not allow assignment to static fields using the class name
itself.


Matlab does not allow the CLASSNAME.STATIC_FIELD syntax for setting, although
it does for getting.  However, they do support a universal syntax which works
for both getting and setting.  In this case you can get or set any static
field of a class from any particular instance of the class.

This universal syntax works in Octave or Matlab:


object = javaObject ('CLASSNAME');

GET:
static_field = object.STATIC_FIELDNAME;
SET:
object.STATIC_FIELDNAME = new_value;


As a concrete example,


jobj = javaObject ('java.lang.Integer', 1);
## Now ask for MAX_VALUE which is a class field of Integer
jobj.MAX_VALUE
ans =    2.1475e+09

which is equivalent to the deprecated
java_get ('java.lang.Integer', 'MAX_VALUE')
warning: java_get is obsolete and will be removed from a future version of
Octave; use structure-like indexing instead
ans =    2.1475e+09


It is usually better to use any getter/setter method that CLASSNAME may have
provided rather than breaking encapsulation to get at the data directly.  You
can call these methods directly with javaMethod() without needing to create an
instance of the class.


javaMethod ('CLASSNAME', 'CLASS_getterFCN')
javaMethod ('CLASSNAME', 'CLASS_setterFCN', value)




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?39074>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]