3 ms·
We've started using Guava recently and one of my favorite changes is that you no longer need try/catches around string conversions in case the OS doesn't suppor
by nfriedly 15y ago
We've started using Guava recently and one of my favorite changes is that you no longer need try/catches around string conversions in case the OS doesn't support utf-8.
- eneveu 15y agoYes. Passing Charset arguments as String not only forces you to deal with the checked UnsupportedEncodingException, but it's also brittle: it's easy to make a typo (is it "utf8", "utf-8", "UTF8", or "UTF-8"?) and get a runtime failure. Guava solves this problem by defining standard Charset constants in com.google.common.base.Charsets ( http://docs.guava-libraries.googlecode.com/git-history/v10.0.1/javadoc/com/google/common/base/Charsets.html http://docs.guava-libraries.googlecode.com/git-history/v10.0... ). Java 7 also brings java.nio.charset.StandardCharsets ( http://download.oracle.com/javase/7/docs/api/java/nio/charset/StandardCharsets.html http://download.oracle.com/javase/7/docs/api/java/nio/charse... ), but Guava will do for now :)