gpt4 book ai didi

java - eclipse : Constructor call must be the first statement

转载 作者:行者123 更新时间:2023-11-29 09:49:30 26 4
gpt4 key购买 nike

即使第一个语句是构造函数调用,为什么我会收到“this(10)”的错误。我正在使用 eclipse 。

public class MaxIndependentSet {
private ArrayList<Integer> inputArr = new ArrayList<Integer>();

public void MaxIndependentSet(int size) {
inputArr.ensureCapacity(size);
}

public void MaxIndependentSet() {
this(10);
}
}

最佳答案

您在构造函数中添加了错误的返回类型 void

构造函数的返回类型是它的类类型,它是隐式声明的,如下所示:

public MaxIndependentSet() {
// blah
}

关于java - eclipse : Constructor call must be the first statement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12171878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com