以下代码无法编译。
@Builder
public class ExampleClass {
private final String field1;
private final int field2;
private ExampleClass (String field1, int field2) throws JAXBException {
// all args constructor that might throw an exception
}
}
因为java: unreported exception javax.xml.bind.JAXBException in default constructor
这个问题的原因可能是build()
方法没有声明它可能会抛出构造函数可能抛出的已检查异常。
有没有一种方法可以让Lombok在不显式实现build()
方法的情况下声明这个异常?
@Builder
public class ExampleClass {
private final String field1;
private final int field2;
private ExampleClass(String field1, int field2) throws JAXBException {
// all args constructor that might throw an exception
}
/**
* I don't want to explicitly declare this
*/
public static class ExampleClass Builder {
public ExampleClass build() throws JAXBException {
return new ExampleClass(field1, field2);
}
}
}