什么是长度和长度()之间的区别? [英] What's the difference between length and length()?

查看:294
本文介绍了什么是长度和长度()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现做一个数组的长度,当你写的东西,如:

  arrayone.length;

然而,对于诸如数组列表或字符串,则写在端部的支架,如用于字符串的长度以下

  stringone.length();

什么是这种情况的重要原因,而且你怎么知道什么时候放支架还是现在?


解决方案

 。长度;

直接的访问字段成员。

 。长度();

调用方法的(即访问器)来访问字段成员。

字符串的情况下,这是可以预料的,因为它的一成不变

I've noticed that when doing the length of an array you write something like:

arrayone.length;

However, for such things as array lists or a string, you write a bracket on the end, such as the following for the length of the String:

stringone.length();

What is the key reason for this and how do you know when to put the brackets or now?

解决方案

.length;

directly accesses a field member.

.length();

invokes a method (i.e. an accessor) to access a field member.

in the case of String, this is to be expected since it's immutable.

这篇关于什么是长度和长度()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆