Is it a better practice to use Reference types or primitive types in Java? -


this question has answer here:

is considered better practice use , manipulate reference types instead of primitive types in java ?

we see java programs mixing both of them, better use primitive types or reference types ? or mix them according needs , criteria choose between primitive or reference type ?

thanks

assuming mean primitive wrapper types (integer, boolean, etc.) , not reference types in general: when have choice (often don't: e.g. using api requires 1 or other, or use them generic type arguments, or want nullable), prefer primitive types, because on whole make code simpler , faster.

be careful if need switch 1 another, because == still compile give different results... usually.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -