dot length in java - finding its definition

前端 未结 7 1218
野趣味
野趣味 2021-01-03 00:31

In which class is the length field defined in Java (e.g. for array length)? Will I be able to see it defined say in Object class?

EDIT : Wh

相关标签:
7条回答
  • 2021-01-03 01:08

    There is no single answer to this question. Anyone can include a length variable in a class, but there's no guarantee that it exists -- or, if it does exist, that it's public -- in any given class. You really just have to read the source for the class you're interested in.

    I will say that in the widely-used JavaBean convention, classes that could reasonably have a length attribute but don't have a public variable length often have getLength() and setLength() methods. That's better than a public variable for a number of reasons that are kind of out of scope for your question, but if you're interested, check out this related SO question.

    0 讨论(0)
提交回复
热议问题