在Matlab中使用Java通用类 [英] Using Java generic classes in Matlab

查看:140
本文介绍了在Matlab中使用Java通用类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能在Matlab中构造一个参数化的类吗?例如在Java中,我可以说 ArrayList< String> myList = new ArrayList< String>()。我已经尝试了 myList = java.util.ArrayList< String>(),但这只是给出了一个错误,表示意外括号或括号。我真的希望使用我自己的参数化类,但是如果我可以获得这个语法,就足够了。

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.

推荐答案

你不能在Matlab中实例化一个参数化的Java类。这是因为Matlab是一种解释型语言。因此,在您的示例中,当您尝试使用

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

此代码立即由Matlab解释并运行(以及编译的Java代码)。但是因为Java有类型擦除,myList的所有类型信息都是立即的丢失。这意味着在Matlab语法类型参数中没有任何意义 - 所以它们在语法上是无效的。

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.

这篇关于在Matlab中使用Java通用类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆