I would like to check constructor arguments and refuse to construct throwing IllegalArgumentException
in case the arguments set is not valid (the values don't fit in expected constraints). How to code this in Scala?
相关问题
- Unusual use of the new keyword
- Get Runtime Type picked by implicit evidence
- how to call a C++ dll from C# windows application
- What's the point of nonfinal singleton objects
- PlayFramework: how to transform each element of a
相关文章
- Gatling拓展插件开发,check(bodyString.saveAs("key"))怎么实现
- RDF libraries for Scala [closed]
- Why is my Dispatching on Actors scaled down in Akk
- Java call constructor from constructor
- How do you run cucumber with Scala 2.11 and sbt 0.
- GRPC: make high-throughput client in Java/Scala
- JUnit continue to assert things after expected exc
- Setting up multiple test folders in a SBT project
In Scala, the whole body of the class is your primary constructor, so you can add your validation logic there.
Scala provides a utility method
require
that lets you write the same thing more concisely as follows:A better approach might be to provide a factory method that gives a
scalaz.Validation[String, Foo]
instead of throwing an exception. (Note: requires Scalaz)