You are viewing a single comment's thread. Return to all comments →
I feel dumb, all this time I tought that s.length() was a method that will itarete the String with a complexity of Big(n).
After some research, I found you are right is just a field and accesing is BigO(1).
I apreciate you responded my commends and help me to find the correct answer.
Thank you again.
For other people that had the same idea as me, this is why the field is access by a method:
-"Method is much more flexible in terms of the future of a class. It is almost never done, except in some very early Java classes, to expose a final constant as a field that can have a different value with each instance of the class, rather than as a method."
Reference and more info:
No, no, nothing is dump here. Learning is never dump. Just something I happened to know. Cheers !
Sometimes comments are gems. Thank you guys. :)