Create new variable or make multiple chained calls?
Posted
by
Rodrigo
on Programmers
See other posts from Programmers
or by Rodrigo
Published on 2012-06-08T14:32:25Z
Indexed on
2012/06/08
16:48 UTC
Read the original article
Hit count: 351
What is the best way to get this attributes, thinking in performance and code quality?
Using chained calls:
name = this.product.getStock().getItems().get(index).getName();
id = this.product.getStock().getItems().get(index).getId();
Creating new variable:
final item = this.product.getStock().getItems().get(index);
name = item.getName();
it = item.getId();
I prefer the second way, to let the code cleaner. But I would like to see some opinions about it.
Thank you!
© Programmers or respective owner