Is it a better practice to use Reference types or primitive types in Java? -
this question has answer here:
- when use wrapper class , primitive type 9 answers
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
Post a Comment