Is using get() excessively in Java inefficient? -


i wondering whether more efficient use get() excessively on object or store return of get() in variable , use that. example, more efficient this:

someobject.setcolor(otherobject.getcolor().r, otherobject.getcolor().g,           otherobject.getcolor().b); 

or store in variable this

color color = otherobject.getcolor(); someobject.setcolor(color.r, color.g, color.b); 

option 1: write code in example 1.

  • the java runtime might or might not optimize code (to turn example 2)
  • harder read

option 2: write code in example 2.

  • does not rely on optimizations java runtime
  • easier read

in experience runtime difference can ignored (you can't measure difference if not executed within giant loop), writing clean , understandable code counts.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -