Howto create javaArray with different derived classes of an abstract superclass?
이전 댓글 표시
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
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개)
카테고리
도움말 센터 및 File Exchange에서 Deploy to Java Applications Using MWArray Data API에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!