After a few reading and questions like this one I was wondering if there was a point in using @NonNull
Android Support Annotation.
I can see a very small warning from Android Studio if I attempt to call a method with a null parameter that is annotated as @NonNull. Just a warning??
What about Unit Testing ? Should I test the method with a null paramter? If I do ... I will get a NullPointerException
and my test will fail.
Let's say we are two developers. One working on the API and one testing the API in all kind of manners. As the second developer, it's my responsibility to test everything so that the API is bullet-proof. That's the whole point of Unit Testing, right ?
So then ... what's the point of the first developer using @NonNull ?
If someone else were to use this API with a null parameter ... then the API would throw a NPE. He then would think : "Urg, that API sucks... NPE !" and he would be right. That naughty dev for not checking if the parameter he sent is null or not should be faced with an IllegalArgumentException because it's his fault not that of the API's!
Am I wrong ?
I thought these annotations would enforce the compiler to show errors like attempting to call methodName(@NonNull Object object) with null parameter
.
Aucun commentaire:
Enregistrer un commentaire