Eclipse seems to be doing the wrong analyzes, the test1 method is fine, but the test2 method gives an error:
Null type security: String expression requires raw conversion to match @NonNull
public class TestCase { public Object o; @NonNull public Object test1() { Object local = new Object(); return local; } @NonNull public Object test2() { o = new Object(); return o; } }
I suspect the problem is that you are returning a value that could be changed by another thread. In this case, this method may return a null reference. You can avoid this by using a temporary variable:
@NonNull public Object test2() { Object tmp = new Object(); o = tmp; return tmp; }
In Eclipse 4.3, you can now use @NonNull for class members, so you can say
@NonNull
@NonNull public Object o;
which will stop the warning, but you must be sure that the element is really initialized!
Source: https://habr.com/ru/post/1499910/More articles:Comparing two hashmap values ββwith keys - javahow to make a text box to accept only 4 digits or digits on iphone - iosPerform the task in the background thread in iOS, continue execution, even when the application enters the background mode: - iosWebSocket Application Architecture - javause transition to MySQL for MongoDB - phpThree.js, PointerLock and collision detection - collision-detectionHow to implement Laravel 4 Partial Views - Binding Data to Partial Views - phpAngularjs ng-repeat element for tag attributes - javascriptHow can I parse the price from Google Play In-app billing - androidDefining a function that computes the covariance matrix of a correlation matrix - covarianceAll Articles