Is there any differences between doing
Field field = something.getSomethingElse().getField();
if (field == 0) {
//do something
}
somelist.add(field);
versus
if (something.getSomethingElse().getField() == 0) {
//do something
}
somelist.add(something.getSomethingElse().getField());
Do references to the field through getters incur a performance penalty or is it the same as referencing an assigned variable? I understand that the variable is just a reference to the memory space, so the getter should just be another way to get at that memory space.
Note that this is an academic question (school of just curious) rather then a practical one.
It's a negligible detriment. Don't concern yourself with it too much or you'll fall prey to premature optimization. If your application is slow, this isn't the reason why.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With