Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android support short circuiting?

This seems to be a stupid question since Java does short circuit, but I remembered how Android doesn't quite use Java in the same sense as I assume, so say in this bit of code I wrote:

... code omitted ...
else if (mimeType.equals("application/x-tar")
     || mimeType.equals("application/x-rar-compressed")
     || mimeType.equals("application/stuffit")
     || mimeType.equals("application/zip")
     || mimeType.equals("application/x-gzip"))

...would it be better for me to put the more common things (zip/rar) before the less common things (tarballs/gzip)?

The fact that I wasn't able to find a similar question on SO probably gives me the answer to this, but better safe than sorry.

like image 743
Tarkenfire Avatar asked Feb 24 '26 11:02

Tarkenfire


1 Answers

Short circuiting is supported with ||.

If you are trying to optimize this case you should try putting each value in a static Set and then check to see if typeSet.contains(mimeType).

like image 88
Eric Schoonover Avatar answered Feb 27 '26 00:02

Eric Schoonover



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!