Second constructor parameter list

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Second constructor parameter list

Jakub Janeček
Hello,

I was trying to do something like this in Scala 2.12:

class Watcher(directory: Path)(listener: () => Unit) extends AutoCloseable {
  ...
}

val watcher = new Watcher(Paths.get("")) { () =>
  ...
}

However I am getting the following compiler error:

Error:(39, 43) missing argument list for constructor Watcher in class Watcher
    val watcher = new ConfigDirectoryWatcher(configFilesDirectory) { () =>

Could someone please try to explain it to me? I don't understand why this does not compile. It can be fixed by surrounding the code with parentheses and moving the braces inside them. I think I used to write such code just fine before so that would mean that it stopped working since Scala 2.12 but I don't know why.

Thanks for any answer. Regards,

--
Jakub Janeček

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Second constructor parameter list

som-snytt

http://scalapuzzlers.com/#pzzlr-036

An apply method can take a block expression, so maybe that is what seems familiar.

scala> import java.nio.file._
import java.nio.file._

scala> case class C(p: Path)(f: () => Unit)
defined class C

scala> C(Paths.get("")){() => ()}
res0: C = C()



On Friday, January 13, 2017 at 7:07:19 AM UTC-8, Jakub Janeček wrote:
Hello,

I was trying to do something like this in Scala 2.12:

class Watcher(directory: Path)(listener: () => Unit) extends AutoCloseable {
  ...
}

val watcher = new Watcher(Paths.get("")) { () =>
  ...
}

However I am getting the following compiler error:

Error:(39, 43) missing argument list for constructor Watcher in class Watcher
    val watcher = new ConfigDirectoryWatcher(configFilesDirectory) { () =>

Could someone please try to explain it to me? I don't understand why this does not compile. It can be fixed by surrounding the code with parentheses and moving the braces inside them. I think I used to write such code just fine before so that would mean that it stopped working since Scala 2.12 but I don't know why.

Thanks for any answer. Regards,

--
Jakub Janeček

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Second constructor parameter list

Roman Janusz
In reply to this post by Jakub Janeček
Essentially, the problem is that the compiler thinks that you're defining an anonymous class and the braces denote the body of that class. You need to put that argument into regular parentheses.

W dniu piątek, 13 stycznia 2017 16:07:19 UTC+1 użytkownik Jakub Janeček napisał:
Hello,

I was trying to do something like this in Scala 2.12:

class Watcher(directory: Path)(listener: () => Unit) extends AutoCloseable {
  ...
}

val watcher = new Watcher(Paths.get("")) { () =>
  ...
}

However I am getting the following compiler error:

Error:(39, 43) missing argument list for constructor Watcher in class Watcher
    val watcher = new ConfigDirectoryWatcher(configFilesDirectory) { () =>

Could someone please try to explain it to me? I don't understand why this does not compile. It can be fixed by surrounding the code with parentheses and moving the braces inside them. I think I used to write such code just fine before so that would mean that it stopped working since Scala 2.12 but I don't know why.

Thanks for any answer. Regards,

--
Jakub Janeček

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Second constructor parameter list

Jakub Janeček
Oh right, thanks, I didn't see that.

On Sunday, January 22, 2017 at 1:16:23 PM UTC+1, Roman Janusz wrote:
Essentially, the problem is that the compiler thinks that you're defining an anonymous class and the braces denote the body of that class. You need to put that argument into regular parentheses.

W dniu piątek, 13 stycznia 2017 16:07:19 UTC+1 użytkownik Jakub Janeček napisał:
Hello,

I was trying to do something like this in Scala 2.12:

class Watcher(directory: Path)(listener: () => Unit) extends AutoCloseable {
  ...
}

val watcher = new Watcher(Paths.get("")) { () =>
  ...
}

However I am getting the following compiler error:

Error:(39, 43) missing argument list for constructor Watcher in class Watcher
    val watcher = new ConfigDirectoryWatcher(configFilesDirectory) { () =>

Could someone please try to explain it to me? I don't understand why this does not compile. It can be fixed by surrounding the code with parentheses and moving the braces inside them. I think I used to write such code just fine before so that would mean that it stopped working since Scala 2.12 but I don't know why.

Thanks for any answer. Regards,

--
Jakub Janeček

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.