What is the main use of "Add contract method to ..." Android Studio

I get the following option, for example "Add a contract to 'setDisplayHomeAsUpEnabled' " , I know that the check is due to NPE getSupportActionBar() can be pressed, but I want to know the actual use of the Method Contract

enter image description here

If I press Enter on this choice, I get:

enter image description here

Any exchange? Any help? It will be appreciated :)

+7
android nullpointerexception annotations
source share
1 answer

This applies to creating method contracts that describe when a method can return null or not null.

IntelliJ / Android Studio can sometimes infer this from the context of code. But when he cannot know for sure, you can specify a method contract that tells the caller what will happen in different circumstances.

Read more about method contracts here .

+5
source share

All Articles