Howto create javaArray with different derived classes of an abstract superclass?

조회 수: 6 (최근 30일)
Dear Community,
I am trying to create a Java Array consisting of objects that belong to the same superclass but are different classes by themselves. In my case I have the following code:
subject_term = javax.mail.search.SubjectTerm('asdasd');
sender_term = javax.mail.search.FromStringTerm('a@asd.de');
term_array = javaArray('javax.mail.search.SearchTerm', subject_term, sender_term);
combined_terms = javax.mail.search.AndTerm(term_array);
When I execute that code, the following error occurs:
Undefined function 'javaArray' for input arguments of type 'javax.mail.search.SubjectTerm'.
In addition to that, I cannot create an Array the following way:
term_array(3, 1) = javax.mail.search.SearchTerm();
Because SearchTerm is an abstract class.
Java exception occurred: java.lang.InstantiationException: javax.mail.search.SearchTerm
Is there a way to typecast a Java object in MATLAB? Or is there another method to create a java array in MATLAB?
Any help would be very appreciated!
Greetings
  댓글 수: 1
Nikhil Sreekumar
Nikhil Sreekumar 2017년 4월 25일
Hi Lewin,
Why is the 2nd and 3rd argument of javaArray aubject_term and sender_term? Shouldn't it be the dimensions? Also shouldn't it be javax.mailsearch.AndTerm(subject_term, sender_term)?
I ran the following code and didn't get any error:
subject_term = javax.mail.search.SubjectTerm('asdasd');
sender_term = javax.mail.search.FromStringTerm('a@asd.de');
term_array = javaArray('javax.mail.search.SearchTerm', 1, 2); % I am not a java expert, so don't know what is the use of dimension in this context
combined_terms= javax.mail.search.AndTerm(subject_term, sender_term)
Thanks
Nikhil

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by