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

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.

主站蜘蛛池模板: 武功县| 许昌县| 尼木县| 乡城县| 遵义县| 上思县| 平南县| 黄山市| 交口县| 梅河口市| 会昌县| 察雅县| 湘潭市| 衢州市| 武强县| 彭州市| 宝应县| 永靖县| 靖西县| 东台市| 大竹县| 塔河县| 开阳县| 泸定县| 景洪市| 确山县| 托里县| 二连浩特市| 子洲县| 漠河县| 富裕县| 襄城县| 舞阳县| 南召县| 建始县| 犍为县| 资源县| 革吉县| 定陶县| 南丹县| 松阳县|