android @nonnull的作用,Android:NullPointerException尽管@NonNull

我正在使用注释来确保参数不为null,假设这会导致编译器检查.

public @Nullable ApplicationAccount accountForKey(@NonNull String key) {

return accounts.get(key);

}

但是,通过运行此代码,我在此行上得到了NullPointerException

java.util.concurrent.ConcurrentHashMap.get (ConcurrentHashMap.java:883)

那么注释有什么意义呢?

如果我像这样写额外的支票,那就更加模糊了

return key!=null?accounts.get(key):null;

Android Studio警告我,检查没用!

更新:完整调用堆栈:

Caused by java.lang.NullPointerException

at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:883)

at co.getcontrol.services.MerchantCenter.accountForKey(MerchantCenter.java:72)

at co.getcontrol.model.customers.CustomersAggregator.loadCustomerDetails(CustomersAggregator.java:91)

at co.getcontrol.model.customers.CustomerDetailsPresenter.callData(CustomerDetailsPresenter.java:39)

at co.getcontrol.reskin.ui.customers.Custom

你可能感兴趣的:(android,@nonnull的作用)