Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

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

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

From: Sylvain

Date: 2 Dec, 2009 22:38:30

Message: 1 of 3

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 :)

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

From: Yair Altman

Date: 3 Dec, 2009 07:32:06

Message: 2 of 3

Sylvain <sylvain.boltz@gmail.com> wrote in message <1eea19c7-391b-4b3d-b4e6-1d9240b40410@m25g2000yqc.googlegroups.com>...
> 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 :)


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
 

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

From: Ben

Date: 7 Nov, 2011 02:23:10

Message: 3 of 3

"Yair Altman" wrote in message <hf7phm$cn9$1@fred.mathworks.com>...
> Sylvain <sylvain.boltz@gmail.com> wrote in message <1eea19c7-391b-4b3d-b4e6-1d9240b40410@m25g2000yqc.googlegroups.com>...
> > 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 :)
>
>
> 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
>

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 :-)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us