“不封闭类”是什么意思?在斯卡拉这里
Hoi,我正在学习 Scala 并尝试将一些 Java 代码转换为 Scala。下面是一些我想翻译的 Java 代码,
public class Note{
protected void addNote(Meeting n) {
//add n to a list
}
}
public abstract class Meeting{
public Meeting(String name, Note note){
note.addNote(this)
}
}
当我将它们翻译成 Scala 时
class Note{
protected[Meeting] addNote(n:Meeting){
//add n to list
}
}
abstract class Meeting(name:String,note:Note){
note.addNote(this)
}
,我在类中遇到了错误 注意:会议不是一个封闭类。
这是什么意思?我尝试过使用 packagename 而不是 Meeting,如下所示:protected[packagename] addNote(n:Meeting),但它不起作用。
Hoi, I am learning scala and trying to translate some Java code to Scala. Here are some of the code below in Java that I want to translate
public class Note{
protected void addNote(Meeting n) {
//add n to a list
}
}
public abstract class Meeting{
public Meeting(String name, Note note){
note.addNote(this)
}
}
when I translate them to Scala
class Note{
protected[Meeting] addNote(n:Meeting){
//add n to list
}
}
abstract class Meeting(name:String,note:Note){
note.addNote(this)
}
then I got an error in class Note : Meeting is not a enclosing class.
what does it mean? I have tried packagename instead of Meeting, like this:protected[packagename] addNote(n:Meeting), but it doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能那样做朋友班。尝试添加一个封闭的包,如下所示:
You can't do friend classes in that way. Try adding an enclosing package, like so: