Using Java generic classes in Matlab

后端 未结 3 1738
慢半拍i
慢半拍i 2021-01-05 07:24

Is it possible to construct a parameterized class in Matlab? For example in Java I could say ArrayList myList = new ArrayList(). I h

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-05 08:02

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

    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.

提交回复
热议问题