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
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 Center および File 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!