Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java generic classes in Matlab

Is it possible to construct a parameterized class in Matlab? For example in Java I could say ArrayList<String> myList = new ArrayList<String>(). I have tried myList = java.util.ArrayList<String>(), but that just gives an error saying "unexpected parenthesis or bracket". I am really looking to use my own parameterized classes, but if I can get the syntax for this, it should be sufficient.

like image 589
Sam Avatar asked Dec 16 '10 17:12

Sam


1 Answers

You can't instantiate a parametrized Java class in Matlab. This is because Matlab is an interpreted language. So, in your example, when you try

myList = java.util.ArrayList<String>()

This code is immediately interpreted and run by Matlab (and the Java code compiled). But because Java has Type Erasure all type information for myList is immediately lost. This means in the context of Matlab syntax type parameters make no sense -- so they are syntactically invalid.

like image 62
Kurt Kaylor Avatar answered Sep 21 '22 06:09

Kurt Kaylor