I have this test code:
def test = null
test.each { }
Why don’t I get any exception?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The implementation of
eachtries to call theiteratormethod of it’s target in a null-safe fashion. Ifeachis called on a null object, or an object without aniteratormethod, nothing happens.I haven’t seen the source code, but it could look something like this§
§ In reality, this method is probably written in Java rather than Groovy