I am facing a use case where I would like to declare a static finalfield with an initializer statement that is declared to throw a checked exception. Typically,
You can use a method annotated with Lombok's @SneakyThrows
public static final ObjectName OBJECT_NAME = createObjectName();
@SneakyThrows(SomeException.class)
private static ObjectName createObjectName() {
return new ObjectName("foo:type=bar");
}
This annotation makes a checked exception behaves like an unchecked one.