这是我要实例化的类(class):
public class GoogleSheetsAPI {
String spreadsheetId;
Sheets service;
String credentialsFile;
public void GoogleSheetsAPI() {
}
public void GoogleSheetsAPI(String spreadsheetId, String credentialsFile) throws Exception {
this.spreadsheetId = spreadsheetId;
this.credentialsFile = credentialsFile;
service = getSheetsService();
}
}
这就是我创建类
GoogleSheetsAPI
的对象的方式GoogleSheetsAPI googleSheetsAPI = new GoogleSheetsAPI(spreadsheetId, credentiialsFile);
最佳答案
构造函数不得具有void
,应为:
public GoogleSheetsAPI(String spreadsheetId, String credentialsFile) throws Exception {
this.spreadsheetId = spreadsheetId;
this.credentialsFile = credentialsFile;
service = getSheetsService();
}
关于java - 无法使用Java中的参数化构造方法实例化对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45229594/