唯一的可能性是捕获Exception并将其转换为RuntimeException,就像SpringJDBC那样的库.
基本上是这样的
public class OriginalLibrary {
public void method1() throws IOException {
...
}
}
public class LibraryWithoutException {
private OriginalLibrary original;
public LibraryWithoutException(OriginalLibrary original) {
this.original = original;
}
public void method1() {
try {
original.method1();
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
}
注意:最好是创建自定义RuntimeException而不是使用标准类.
或者你的api:
public class APIWrapperNoException {
private APIWrapper api;
public APIWrapperNoException(APIWrapper api) {
this.api = api;
}
public String getAppBuilds(String report_changed_since,
String only_latest,
String include_in_progress) {
try {
return api.getAppBuilds(report_changed_since,
only_latest, include_in_progress);
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
}