为什么string.length减()的方法,和int []长度的属性? [英] Why is string.length() a method, and int[].length a property?
本文介绍了为什么string.length减()的方法,和int []长度的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么string.length减()的方法,和int []长度属性(见下文)?
INT [] = NUMS {2,4,7,12,43};
串词=你好,世界;System.out.length(nums.length);
System.out.length(phrase.length());
解决方案
我不认为必须有一个很好的理由,我想可能有很多原因。
但是之一是通过使字符串#长度()
的属性,它可以在一个接口被声明,而不是(在此情况下的 的CharSequence
)。接口不能声明公用实例字段。
Why is String.length() a method, and int[].length a property (see below)?
int[] nums = {2,4,7,12,43};
String phrase = "Hello, world.";
System.out.length(nums.length);
System.out.length(phrase.length());
解决方案
I don't think there has to be a good reason, and I think there could be many reasons.
But one is that by making String#length()
a property, it can be declared in an interface instead (in this case CharSequence
). Interfaces cannot declare public instance fields.
这篇关于为什么string.length减()的方法,和int []长度的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文