Scala 缓冲区:大小或长度? [英] Scala Buffer: Size or Length?

查看:37
本文介绍了Scala 缓冲区:大小或长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个可变的 Buffer 并且需要找出它有多少个元素.

I am using a mutable Buffer and need to find out how many elements it has.

sizelength 方法都被定义,继承自不同的特征.

Both size and length methods are defined, inherited from separate traits.

是否存在任何实际性能差异,或者可以将它们视为完全同义词?

Is there any actual performance difference, or can they be considered exact synonyms?

推荐答案

它们是同义词,主要是 Java 决定集合 sizelength 用于ArrayString.一个总是根据另一个定义,您可以通过查看源代码轻松了解哪个是哪个,scaladoc 上提供了其链接.只需找到定义特征,打开源代码,然后搜索 def sizedef length.

They are synonyms, mostly a result of Java's decision of having size for collections and length for Array and String. One will always be defined in terms of the other, and you can easily see which is which by looking at the source code, the link for which is provided on scaladoc. Just find the defining trait, open the source code, and search for def size or def length.

这篇关于Scala 缓冲区:大小或长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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