在尝试初始化数组时,只能在初始值设定项中使用数组常量?

时间:2013-04-29 00:52:04

标签: java arrays initialization

鉴于以下内容:

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那样做,但它不起作用。有什么方法吗?

此致

1 个答案:

答案 0 :(得分:1)

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

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