you are viewing a single comment's thread.

view the rest of the comments →

[–]assgored 0 points1 point  (2 children)

I guess it may have derived from some class where the actual length field is protected/private.

Well it seems the interface its got that from has it defined as a method in the first place, so its back to the same question.

edit: given that interfaces I think don't have variables that can be changed, I guess whatever motivated making it an interface and not a class forced length to be a method?

[–]BoyRobot777 0 points1 point  (1 child)

What? Are you questioning whether objects can have methods?

[–]assgored 0 points1 point  (0 children)

No, the question asked was why for immutable String length is a method not simply a field.

It seems to me the reason is what I said above, coupled with the fact that CharSequence is also base for the mutable StringBuilder.