简体   繁体   中英

Scala objects masked as methods vs actual method (Stream.cons)

I have been going through the Scala Stream collection API and I have noticed that Stream.cons is implemented as an embedded object. What advantage does this have over implementing it as a function? Under what circumstances should one consider using this technique?

Cheers.

作为一个对象,除了apply之外,它还定义了unapply ,它允许你对它进行模式匹配。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM