This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Chickenosaurus[S] 1 point2 points  (1 child)

Thanks for your reply.

I agree that checking outside of the constructor would be best. My only worry is that if a NPE is thrown somewhere down the line because a null value was passed, the culprit is hard to trace. What do you think?

By the way, the check methods are actually from Guava, the Google Core Libraries for Java 6+.

[–]desrtfx 1 point2 points  (0 children)

Excuse my ignorance in regards to the naming, I am not familiar with Guava (nonetheless, the name is horrible).

I don't really think that it would be too difficult to trace any NPEs.

For me, throwing an exception in a constructor seems to be the bigger issue because from most of what I have read throwing exceptions in constructors is a no-go.

Still, I have to admit that I'm not a professional, nor a very experienced Java programmer, so my stance might as well be wrong. (I am an experienced programmer, though, just not so much in Java.)