Java class access pitfalls | Undocumented Matlab
[Condensed mirror of the pitfalls, see the page for details]
Mon Jun 1 14:09:12 2015 - permalink -
1. Forgetting or mistyping the package name: Since Java is case-sensitive, the package name must be exact.
2. Mistyping the class name. As with package names, Java class names are also case-sensitive. Beware of cases of O/0 (capital-”o” vs. the digit zero), and I/l/1 (capital-”i” vs. lowercase “L” vs. the digit 1). Also note whether the class name includes the underscore (“_”) character.
3. Using a Java class that was compiled using a newer JDK major-version than the JVM used in Matlab.
4. Forgetting to update the Java classpath.
5. Dependency #1: A class that depends on any other class that is not on the current Java classpath (either dynamic or static).
6. Dependency #2: A class on the static Java classpath that depends on another class which is on the dynamic Java classpath. All static classes must depend only on other static classes, since the static classpath is processed before the dynamic one, when the JVM is launched at Matlab startup.
7. Non-public class – Matlab can only access public classes. If the class is private, protected or has package visibility (by not specifying any visibility modifier at all), then the class would not be loadable by Matlab, only by other Java classes. So remember to add the public keyword in the definition of all the Java classes that you wish to directly use in Matlab.
8. Non-public constructor – Matlab can only create objects for non-static classes that have public constructors. If all the class constructors are non-public, then Matlab cannot create a class instance object. In such a case we would get a misleading error message, that at least hints that the problem is with the constructor.