Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am getting following option like "Add method contract to 'setDisplayHomeAsUpEnabled'", I know that inspection is because of NPE can throw by getSupportActionBar() but I want to know actual use of Method Contract

enter image description here

If I Press Enter on that selection, I am getting:

enter image description here

Any Sharing? Any Help? It will appreciated :)

like image 780
Pratik Butani Avatar asked Mar 16 '16 06:03

Pratik Butani


1 Answers

This relates to creating method contracts that describe when a method may return null or not null.

IntelliJ/Android Studio is sometimes able to to infer this from the context of the code. But when it is not able to 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.

like image 57
Doug Stevenson Avatar answered Sep 28 '22 13:09

Doug Stevenson