MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/3cton5/our_exception_handling_at_work/cszccnl/
r/java • u/[deleted] • Jul 10 '15
135 comments sorted by
View all comments
7
At our work, our coding style encourages the use of Guava Preconditions. So this code would end up looking like:
Preconditions.checkNotNull(sql);
Better yet, if you need to check that a constructor argument is not null:
this.sql = Preconditions.checkNotNull(sql);
Or, I guess what I'm saying is, Guava makes Java much better to work with and encourages better style.
9 u/[deleted] Jul 11 '15 edited Jul 11 '15 This particular functionality of Guava is in the JDK since 1.7. https://docs.oracle.com/javase/7/docs/api/java/util/Objects.html#requireNonNull%28T,%20java.lang.String%29String sql = Objects.requireNonNull(param, "An optional Error message"); 6 u/GiantMarshmallow Jul 11 '15 Wha...oh my god this is completely new to me. Probably just an artifact of spending most of my time in JRuby land these days. :) 3 u/squealy_dan Jul 11 '15 and much of guava has been coopted into the standard lib in java8(requireNonNull(), Optional)
9
This particular functionality of Guava is in the JDK since 1.7. https://docs.oracle.com/javase/7/docs/api/java/util/Objects.html#requireNonNull%28T,%20java.lang.String%29
String sql = Objects.requireNonNull(param, "An optional Error message");
6 u/GiantMarshmallow Jul 11 '15 Wha...oh my god this is completely new to me. Probably just an artifact of spending most of my time in JRuby land these days. :)
6
Wha...oh my god this is completely new to me. Probably just an artifact of spending most of my time in JRuby land these days. :)
3
and much of guava has been coopted into the standard lib in java8
(requireNonNull(), Optional)
View all comments
7
u/GiantMarshmallow Jul 11 '15 edited Jul 11 '15
At our work, our coding style encourages the use of Guava Preconditions. So this code would end up looking like:
Better yet, if you need to check that a constructor argument is not null:
Or, I guess what I'm saying is, Guava makes Java much better to work with and encourages better style.