且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java在构造函数中初始化一个int数组

更新时间:2023-09-18 17:59:22

private int[] data = new int[3];

这已经将数组元素初始化为0.你不需要在构造函数中重复这一点。

This already initializes your array elements to 0. You don't need to repeat that again in the constructor.

在你的构造函数中它应该是:

In your constructor it should be:

data = new int[]{0, 0, 0};