1

I executed this code block in a IntelliJ worksheet (Community Edition EAP 15#143.379.11 with Scala plugin 1.9.4 on JDK 1.8.0_66) ,

class Plant
class Fruit extends Plant
class Apple extends Fruit

class Box[T <: Fruit](var item: T) {
  def get: T = item
  def replace(item: T): Unit = this.item = item
}

val appleBox = new Box(new Apple)
println(appleBox.get) // error

and IntelliJ reported this error during worksheet compilation and stopped,

Error:(22, -59) side-effecting nullary methods are discouraged: suggest defining as `def get$$instance$$res0()` instead
println(appleBox.get);//
    ^

How do I disable this error or change it to warning and let me continue? I am using IntelliJ . Thanks

thlim
  • 2,908
  • 3
  • 34
  • 57
  • http://stackoverflow.com/questions/24781394/what-does-the-following-warning-mean-side-effecting-nullary-methods-are-discou – Michael Zajac Oct 27 '15 at 12:54

1 Answers1

0

To avoid an error just remove println, Scala Worksheet will print the object for you.

    val appleBox = new Box(new Apple)
    appleBox.get

    appleBox: Box[Apple] = Box@4109bbc4
    res0: Apple = Apple@6e2e3a8b

PS: I do not get the error you are reporting in the latest EAP Scala Plugin (1.9.272)

kukido
  • 10,431
  • 1
  • 45
  • 52
  • Thanks but that's not exactly the answer I am looking for. Yes, IntelliJ prints the object but what if I want to stream the out to a file via FileOutStream.write(...) I would have hit the same error again. Btw, where do you find the 1.9.272 plugin? I could not find it in https://confluence.jetbrains.com/display/SCA/Scala+Plugin+EAP+15 – thlim Oct 27 '15 at 06:39
  • @thlim "How do I disable this error or change it to warning and let me continue?" - that was your question. I apologize if I misunderstood and it as not the answer you were looking for. The original question did not have anything about FileOutStream. – kukido Oct 27 '15 at 17:22
  • Apology not needed. I am grateful you answered. I am looking for a conclusive solution in case I have a FileOutputStream or anything similar to println(...) that causes the error worksheet cannot be used. maybe i need the scala plugin you are using. – thlim Oct 28 '15 at 03:55