【问题标题】:Array constants can only be used in initializers when trying to initialize an array? [duplicate]尝试初始化数组时,数组常量只能在初始化程序中使用吗? [复制]
【发布时间】:2013-04-29 00:52:03
【问题描述】:

鉴于以下情况:

public class Actions 
{


    private MyMatrix matrix_1;
    private MyMatrix matrix_2;
    private MyMatrix transformMatrix;
    private final int VW = 40;
    private final int VH = 40;

    public static double[][] translateMatrixArr;


    public Edge doTransofrm(double xPoint,double yPoint,Edge myEdge,int transformType)
    {
        switch(transformType)
        {
        case 1:
            // initializations 
            Actions.translateMatrixArr = {{1.,0.,xPoint},{0.,1.,yPoint},{0.,0.,1.}};
            break;
        case 2:
            Actions.translateMatrixArr = // something else 
            break;
        case 3:
            Actions.translateMatrixArr = // something else

        }

        return null;
    }


...


}

我试着像@joschi 所说的here 那样做,但它不起作用。有什么办法吗?

问候

【问题讨论】:

  • “我试着像@joschi 在这里所说的那样做,但它不起作用”在什么意义上不起作用?

标签: java arrays initialization


【解决方案1】:

您需要使用new 来创建数组实例:

Actions.translateMatrixArr = new double[][]{
    new double[] {1.,0.,xPoint}
,   new double[] {0.,1.,yPoint}
,   new double[] {0.,0.,1.}
};

【讨论】:

    猜你喜欢
    • 2011-11-18
    • 1970-01-01
    • 2011-09-14
    • 2014-10-09
    • 1970-01-01
    • 2016-10-28
    • 2019-06-24
    • 2015-08-25
    • 2020-10-24
    相关资源
    最近更新 更多