Creating an array while passing it as an argument in Java

后端 未结 4 690
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 19:09

Is there a way to create an array of objects as part of a constructor or method? I\'m really not sure how to word this, so I\'ve included an example. I have an enum, and

4条回答
  •  春和景丽
    2020-12-18 20:06

    You can try with new float[] { ... }.

    public enum KeyboardStuff {
    
        QWERTY(1, new float[] {0.5f, 1.3f, 23.1f}, 6);
        DVORAK(5, new float[] {0.1f, 0.2f, 4.3f, 1.1f}, 91);
        CHEROKEE(2, new float[] {22.0f}, 11);
    
        private int number, thingy;
        private float[] theArray;
    
        private KeyboardStuff(int i, float[] anArray, int j) {
            // do things
        }
    
    }
    

提交回复
热议问题