Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Enum type inside a class (matlab <-> java interface)

78 views
Skip to first unread message

Sylvain

unread,
Dec 2, 2009, 5:38:30 PM12/2/09
to
Hello,

Let's say I want to define this in java :

package internet;
public class Downloader {
public enum DownloadStatus { INITIALIZING, IN_PROGRESS, COMPLETE };
}

How do I access the enum from matlab.

It seems that it works if the enum is defined outside of any class
(says Andrew here : http://stackoverflow.com/questions/1223795/using-java-enums-or-public-static-fields-in-matlab
) . But In this case, nothing seems to work in matlab

import internet.Downloader.DownloadStatus; does not work, it is not
recognized
internet.Downloader.DownloadStatus; does not work
internet.Downloader.DownloadStatus.INITIALIZING does not work
creating an empty object Downloader then trying to access
Downloadstatus does not work
I tried even the most stupid things, can't make it work

Why I want to do this ? Because there is a method in a java library
that asks for an enum type defined inside a class, so I need by any
means to create this enum type in matlab and pass it to the method as
a parameter.

Thanks for your help :)

Yair Altman

unread,
Dec 3, 2009, 2:32:06 AM12/3/09
to
Sylvain <sylvai...@gmail.com> wrote in message <1eea19c7-391b-4b3d...@m25g2000yqc.googlegroups.com>...


You can try 'internet.Downloader$DownloadStatus' within the awtinvoke or javaMethod functions (this should work but I'm not 100% certain).

Alternately, use the method I used for system-tray messages, which has the same issue: http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/

Yair Altman
http://UndocumentedMatlab.com

Ben

unread,
Nov 6, 2011, 9:23:10 PM11/6/11
to
"Yair Altman" wrote in message <hf7phm$cn9$1...@fred.mathworks.com>...
Based on Yair's suggestion, I found that using the valueOf() method with javaMethod works. For example, javaMethod('valueOf', 'internet.Downloader$DownloadStatus', 'INITIALIZING'). This solves a similar issue I was having, so thanks for the suggestion.

Ben :-)
0 new messages