bugGNU Octave - Bugs: bug #39074, java_get deprecated ok?

 
 

bug #39074: java_get deprecated ok?

Submitter:  Ernst Reissner <ernstreissner>
Submitted:  Sun 26 May 2013 10:41:34 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Ernst Reissner Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 17 Jul 2013 10:38:22 PM UTC, 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)



Rik <rik5>
Group administrator
Sun 26 May 2013 08:17:02 PM UTC, comment #1: 

Confirmed.

In the io package, in e.g., private/__JOD_spsh2oct__.m, there are several examples that still need java_get.

BTW java_get (and java_set) will be kept for the next two stable releases so no worries for the time being; but I agree a replacement for static fields is warranted.

Philip Nienhuis <philipnienhuis>
Group Member
Sun 26 May 2013 10:41:34 AM UTC, original submission:  


java_get is deprecated now and it is advised to use dot notation instead: instance.fieldname.
But java_get is also used for static access like Class.fieldname.

Well but at least for me, for static fields this does not work.

So there are two ways: sticking to java_get and undeprecating
or providing Class.fieldname.


Ernst Reissner <ernstreissner>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by ernstreissner (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-07-17 rik5 Open/ClosedOpen Closed
    2013-05-26 philipnienhuis StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code