gpt4 book ai didi

dart - 构造函数中的语法错误

转载 作者:行者123 更新时间:2023-12-03 04:31:51 25 4
gpt4 key购买 nike

以下代码

class MemberException extends ServerException {
String message;
MemberException(message) {
super(message);
}
}

class ServerException implements Exception {
String message;
ServerException(this.message);
}

产生以下(有点无用)错误消息

Too few arguments in implicit super() constructor invocation in '(String) -> dynamic'

最佳答案

正确的格式是:

class MemberException extends ServerException {
String message;
MemberException(message) : super(message) {
// constructor body
}
}

您需要在调用构造函数主体之前初始化super。
引用: http://www.dartlang.org/docs/dart-up-and-running/contents/ch02.html#ch02-constructors(请参阅初始化器部分)

关于dart - 构造函数中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14645144/

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