Scala companion class warning

后端 未结 2 574
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 04:07

I am new to Scala programming, can someone explain me below warning reason?

\"Scala-Companion-Warning\" I trie

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-12 04:10

    This is specific to the REPL (Read Evaluate Print Loop), since it can't know when user input ends.

    Use :paste to get around it :

    scala> class A {}
    defined class A
    
    scala> object A {}
    defined object A
    warning: previously defined class A is not a companion to object A.
    Companions must be defined together; you may wish to use :paste mode for this.
    
    scala> :paste
    // Entering paste mode (ctrl-D to finish)
    
    class A {}
    object A {}
    
    // Exiting paste mode, now interpreting.
    
    defined class A
    defined object A
    

提交回复
热议问题