官术网_书友最值得收藏!

Object-oriented aspects of functions

We mentioned that Scala is a fusion of object-oriented and functional paradigms. Because of this, Scala has functions as a first-class element of the language. Also because of this, everything is an object in Scala. This is partly related to the fact that everything is an object or a primitive type in the JVM, but Scala goes further and also hides primitives behind objects.

It turns out that functions are also objects! Depending on the number of arguments, they extend one of the special traits. Also because of their object-oriented nature, it is possible to implement additional features by defining additional methods on the implementing class. This is how partial function is implemented. It is also natural to utilize companion objects to define common logic for functions so that it can be easily reused. It's even possible to write some custom implementation of a function, though it is seldom a good idea.

Each of these aspects is worth a deep dive, but to really understand them, we need to start with some implementation details.

主站蜘蛛池模板: 沙田区| 奉新县| 迭部县| 苍南县| 肇东市| 牙克石市| 郑州市| 五家渠市| 阳西县| 福鼎市| 广宁县| 丰城市| 鸡西市| 广南县| 公安县| 龙山县| 新乐市| 东平县| 崇信县| 张家港市| 都匀市| 潞西市| 景谷| 松原市| 潍坊市| 无为县| 霍山县| 永仁县| 南部县| 庄浪县| 沅江市| 祁门县| 汤原县| 辽中县| 平泉县| 安塞县| 上栗县| 深泽县| 揭阳市| 通河县| 孙吴县|