Inner classes require a conversion of '.' to '$' in Matlab.
This may be due to the way the Java compiler stores the internal objects of the class. It behaves similarly for inner classes (e.g. javax.swing.plaf.basic.BasicTextUI$UpdateHandler ). Matlab is not as smart as the JVM to automatically convert these internal "$" to ".". Therefore, we cannot use the usual simple dot notation in these cases in Matlab, and since "$" is an invalid character in the Matlab syntax, we must resort to using "$" in javaObject , javaMethod , awtinvoke and their relatives. For instance:
Java: InnerClass c = new com.example.test.SomeEnum.InnerClass; MATLAB: c = javaObject('com.example.test.SomeEnum$InnerClass')
Enumerations require a similar conversion. to '$' in Matlab. But the MATLAB javaObject function calls the constructor of the class, and since the enumerations do not have a constructor, we get the following error:
Java class does not have a constructor with the corresponding signature
Fortunately, enum has a built-in valueOf() method that we can use with javaMethod :
Java: SomeEnum e = com.example.test.SomeEnum.MY_FAVORITE_ENUM; MATLAB: e = javaMethod('valueOf','com.example.test$SomeEnum','MY_FAVORITE_ENUM');
Similarly:
Java: int n = com.example.test.Foo.MAX_FOO; MATLAB: n = javaMethod('com.example.test.Foo$MAX_FOO')
Static fields can be obtained directly in Matlab using simple dot notation:
redColor = java.awt.Color.red;
A complete list of static fields can be obtained using the built-in Matlab struct function:
>> staticFields = struct(java.awt.Color.red) staticFields = white: [1x1 java.awt.Color] WHITE: [1x1 java.awt.Color] lightGray: [1x1 java.awt.Color] LIGHT_GRAY: [1x1 java.awt.Color] gray: [1x1 java.awt.Color] GRAY: [1x1 java.awt.Color] darkGray: [1x1 java.awt.Color] DARK_GRAY: [1x1 java.awt.Color] black: [1x1 java.awt.Color] BLACK: [1x1 java.awt.Color] red: [1x1 java.awt.Color] RED: [1x1 java.awt.Color] pink: [1x1 java.awt.Color] PINK: [1x1 java.awt.Color] orange: [1x1 java.awt.Color] ORANGE: [1x1 java.awt.Color] yellow: [1x1 java.awt.Color] YELLOW: [1x1 java.awt.Color] green: [1x1 java.awt.Color] GREEN: [1x1 java.awt.Color] magenta: [1x1 java.awt.Color] MAGENTA: [1x1 java.awt.Color] cyan: [1x1 java.awt.Color] CYAN: [1x1 java.awt.Color] blue: [1x1 java.awt.Color] BLUE: [1x1 java.awt.Color] OPAQUE: 1 BITMASK: 2 TRANSLUCENT: 3
The MATLAB javaObject function may not work if the default constructor is private (hidden) and javaMethod probably will not work either. If a class with static methods is nested, you might be out of luck. For my systray utility on File Exchange, I used the reflection approach as described in this post: http://UndocumentedMatlab.com/blog/setting-system-tray-popup-messages/
Credit: edited by Mark Mikofsky