3

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.

JohannesDienst
  • 455
  • 4
  • 11
echo
  • 99
  • 1
  • 2
  • 4

1 Answers1

1

You can't do friend classes in that way. Try adding an enclosing package, like so:

package translation 
class Note{
  protected[translation] def addNote(n:Meeting){
    //add n to list
  }
}
abstract class Meeting(name:String, note:Note){
  note.addNote(this)
}
sblundy
  • 60,628
  • 22
  • 121
  • 123