arrays - JAVA (Generics, Iterable Interface, Initialize 2-dim Array) 类型不匹配:无法从 int 转换为 Matrix
问题描述
@SuppressWarnings("unchecked")
Matrix<Integer>[][] m = (Matrix<Integer>[][]) new Matrix[][] {
{2,34,532,12},
{923,6,0,67},
{32,324,3,13}
};
有人能告诉我如何以不同的方式初始化 3x4 矩阵吗?我在所有三行中都不断收到“类型不匹配:无法从 int 转换为 Matrix”错误。
解决方案
最好知道您正在使用什么语言以及您尝试使用什么 Matrix 类,但看起来您做的事情有点错误。
# create an int array
int[] i = new int[]{1, 2, 3}
# Create a 2d int array
int[][] i = new int[][]{
{1, 2},
{3, 4}
}
# what you have is creating a 2d array, of Matrix<Integer>
Matrix<Integer>[][]
# So either just use a normal int 2d array, or i believe the syntax in C++ is:
Matrix<Integer, 3, 4>
推荐阅读
- mongodb - 如何根据另一个数组字段的数组更新 MongoDB 数组字段
- python - 在 Windows 7 32 位 Python 上出现内存错误的任何明显原因?
- apache-kafka - Apache flink Confluent org.apache.avro.generic.GenericData$Record 无法转换为 java.lang.String
- macos - 如何在 MacOS 中打开本地网络端口?
- python - 如何用python在一个类别中创建一个类别?
- git - 运行 git checkout 时不小心省略了“--”
- macos - 为用户使用数据库创建一个安全的环境
- python - Python Internet Explorer 驱动程序使用自己的代理而不是我设置的代理
- excel - Excel VBA URLDownloadToFile 不检索完整文件(Sharepoint API)
- c# - 使用 C++/CLI 向 C# 公开 C++ 非托管代码类指针