Idea Transcript
Scala Language › Scala - User
Login Register
Second constructor parameter list ‹ Previous Topic
Next Topic
›
Classic
List
Jakub Janeček
4 messages
Threaded Jan 13, 2017; 10:05pm
Second constructor parameter list
Options
Reply | Threaded | More
Hello, I was trying to do something like this in Scala 2.12:
2 posts
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.
som-snytt
Jan 21, 2017; 11:52am
Re: Second constructor parameter list
Reply | Threaded | More
http://scalapuzzlers.com/#pzzlr-036 An apply method can take a block expression, so maybe that is what seems familiar. 490 posts
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) { () => ... [ show rest of quote]
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. 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]. Thanks for any answer. Regards, For more options, visit https://groups.google.com/d/optout.
Roman Janusz
-Jan 22, 2017; 7:15pm Re: Second constructor parameter list Jakub Janeček
Reply | Threaded | More
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.
65 posts
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) { () => ... [ show rest of quote]
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. 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]. Thanks for any answer. Regards, For more options, visit https://groups.google.com/d/optout.
Jakub Janeček
-Jan 23, 2017; 2:40pm Re: Second constructor parameter list Jakub Janeček
Reply | Threaded | More
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. 2 posts
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:
... [ show rest of quote]
Error:(39, 43) missing argument list for constructor Watcher in class Watcher
-- val watcher = new ConfigDirectoryWatcher(configFilesDirectory) { () => 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]. ... [ show rest of quote] 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 For more options, visit https://groups.google.com/d/optout.
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.
« Return to Scala - User | 109 views
Thanks for any answer. Regards, -Jakub Janeček
Free forum by Nabble - Scala Resume Examples - Resume Templates
Disable Popup Ads | Edit this page