How to handle a static final field initializer that throws checked exception
If you don’t like static blocks (some people don’t) then an alternative is to use a static method. IIRC, Josh Bloch recommended this (apparently not in Effective Java on quick inspection). public static final ObjectName OBJECT_NAME = createObjectName(“foo:type=bar”); private static ObjectName createObjectName(final String name) { try { return new ObjectName(name); } catch (final SomeException exc) … Read more