Hacker News new | past | comments | ask | show | jobs | submit login

Yes and there are a number of libraries (commons-lang, Spring, etc.) which include Assert classes for things like Assert.notNull(), Assert.notEmpty(Collection<T>), etc.

This seems like recognition that such commonly used library functionality might also be useful to be in the base API.

Though I would think it would make more sense for Objects.nonNull() to throw IllegalArgumentException, not a NPE.




One could make the "Aren't these just libraries?" argument for the collections stuff introduced in 1.2, but this standardization served a legitimate purpose by facilitating rich inter-component/framework interoperability. While I don't dispute the benefits of using this new Objects class, provides methods used in implementations, not common API representations. So, I'd argue that the Java ecosystem isn't much better off for it. This isn't to say that I'm not happy that it's there, but I don't think it's nearly as noteworthy as new language features, underlying JVM performance improvements, etc.

As an aside, I was surprised that the article did not take advantage of static imports to rid the code of the "Objects" references. One could just say:

if (notNull(foo).equals("bar")){...}


"As an aside, I was surprised that the article did not take advantage of static imports..."

I also much prefer the readability of static imports, but it won't work for the "equals," "toString" and "hashCode" methods, obviously.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: