4 ms·
Yes. 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 t
by eneveu 15y ago
Yes. 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 :)