scala> import com.google.common.base.Preconditions.checkArgument
import com.google.common.base.Preconditions.checkArgument
scala> checkArgument(! Nil.isEmpty, "failure")
<console>:6: error: ambiguous reference to overloaded definition,
both method checkArgument in object Preconditions of type
(Boolean,java.lang.String,java.lang.Object*)Unit
and method checkArgument in object Preconditions of type (Boolean,Any)Unit
match argument types (Boolean,java.lang.String)
checkArgument(! Nil.isEmpty, "scdc")
It would be nice to have this cleanly work with Scala. Any suggestions besides
adding an empty array as a third argument?
BTW, I would put this up on StackOverflow, but this appears to have a change to
Guava to make this work, more than having it work in my code.
What about adding Preconditions.checkArgument() that takes a boolean and a
String, not an Object?
Blair
Have a look here:
http://daily-scala.blogspot.com/2010/03/assert-require-assume.html
> --
> guava-...@googlegroups.com.
> http://groups.google.com/group/guava-discuss?hl=en
> unsubscribe: guava-discus...@googlegroups.com
>
> This list is for discussion; for help, post to Stack Overflow instead:
> http://stackoverflow.com/questions/ask
> Use the tag "guava".
>
--
guava-...@googlegroups.com.
http://groups.google.com/group/guava-discuss?hl=en
unsubscribe: guava-discus...@googlegroups.com
This list is for discussion; for help, post to Stack Overflow instead:
http://stackoverflow.com/questions/ask
Use the tag "guava".
The reason that I don't use require is that it prepends the some text to
the exception message text that I don't want:
def require(requirement: Boolean) {
if (!requirement)
throw new IllegalArgumentException("requirement failed")
}
def require(requirement: Boolean, message: Any) {
if (!requirement)
throw new IllegalArgumentException("requirement failed: "+ message)
}
Kinda minor thing, but it bugs me if I want to customize an exception
message that is thrown to client code.
Blair