我目前正在为我工作场所使用的 SOAP 网络服务编写 Java-API。
Web 服务类是使用Axis2生成的,它们可以返回null. 因为我不想null在我的业务逻辑级别处理 -references,所以我使用Optional<>as 返回类型。
例如:
/**
* Reads account-data to given accountId.
*
* @param accountId
* the primary key of table 'account'
* @return the account wrapped as an Optional<>, if an account with primary key 'accountId' exists; Optional.empty(), else
*/
public Optional<Account> readAccount(long accountId) throws RemoteException, ServiceFaultException {
// prepare SOAP-Request
ReadAccount request = new ReadAccount();
request.setAccountId(accountId);
// execute SOAP-Request
ReadAccountResponse response = accountService.readAccount(request);
// process Response
Optional<Account> account = Optional.ofNullable(response.getAccount());
return account;
}
上面的方法执行一个网络服务操作来搜索数据库中的一些帐户记录。如果没有找到具有匹配参数的帐户accountId,则方法调用response.getAccount()可以返回null。
是否有更简洁的方法来编写 Javadoc @return?
特别是对于短语“wrapped as an Optional<>”?
翻翻过去那场雪
ibeautiful
相关分类