if (!obj instanceof SomeEnum) throw new IllegalArgumentException()Clearly, the intention was to throw
// do something with obj.name()
IllegalArgumentException
if obj
is not the correct type, but instead the code was throwing MissingMethodException
from the access to obj.name()
.The problem is missing braces. What Groovy is actually evaluating is
if (false instanceof SomeEnum)
!obj
evaluates to false as obj
is not null. The correct code would be:if (!(obj instanceof SomeEnum)) throw new IllegalArgumentException()
No comments:
Post a Comment