The following code creates a Java string object, which however is automatically converted to an Octave string:
octave> s = javaObject('java.lang.String', 'Hello OctaveString') s = Hello OctaveString
Note that the java package automatically transforms the Java String object to an Octave string. This means that you cannot apply Java String methods to the result.
This "auto boxing" scheme seems to be implemented for the following Java classes:
If you instead create an object for which no "auto-boxing" is implemented,
javaObject
returns the genuine Java object:
octave> v = javaObject('java.util.Vector') v = <Java object: java.util.Vector> octave> v.add(12); octave> v.get(0) ans = 12
If you have created such a Java object, you can apply all methods of the Java class to the returned object. Note also that for some objects you must specify an initializer:
% not: octave> d = javaObject('java.lang.Double') error: [java] java.lang.NoSuchMethodException: java.lang.Double % but: octave> d = javaObject('java.lang.Double',12.34) d = 12.340