Programming in Scala: A Comprehensive Step-by-Step Guide, Third Edition by Martin Odersky & Lex Spoon & Bill Venners
Author:Martin Odersky & Lex Spoon & Bill Venners [Odersky, Martin]
Language: eng
Format: azw3
Publisher: Artima Press
Published: 2016-04-27T04:00:00+00:00
20.2 Type members
As you can see from the example in the previous section, the term abstract type in Scala means a type declared (with the "type" keyword) to be a member of a class or trait, without specifying a definition. Classes themselves may be abstract, and traits are by definition abstract, but neither of these are what are referred to as abstract types in Scala. An abstract type in Scala is always a member of some class or trait, such as type T in trait Abstract.
You can think of a non-abstract (or "concrete") type member, such as type T in class Concrete, as a way to define a new name, or alias, for a type. In class Concrete, for example, the type String is given the alias T. As a result, anywhere T appears in the definition of class Concrete, it means String. This includes the parameter and result types of transform, initial, and current, which mention T when they are declared in supertrait Abstract. Thus, when class Concrete implements these methods, those Ts are interpreted to mean String.
One reason to use a type member is to define a short, descriptive alias for a type whose real name is more verbose, or less obvious in meaning, than the alias. Such type members can help clarify the code of a class or trait. The other main use of type members is to declare abstract types that must be defined in subclasses. This use, which was demonstrated in the previous section, will be described in detail later in this chapter.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8296)
Test-Driven Development with Java by Alan Mellor(6705)
Data Augmentation with Python by Duc Haba(6612)
Principles of Data Fabric by Sonia Mezzetta(6367)
Learn Blender Simulations the Right Way by Stephen Pearson(6261)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(6127)
Hadoop in Practice by Alex Holmes(5958)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5806)
RPA Solution Architect's Handbook by Sachin Sahgal(5526)
Big Data Analysis with Python by Ivan Marin(5353)
The Infinite Retina by Robert Scoble Irena Cronin(5223)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5144)
Pretrain Vision and Large Language Models in Python by Emily Webber(4312)
Infrastructure as Code for Beginners by Russ McKendrick(4074)
Functional Programming in JavaScript by Mantyla Dan(4038)
The Age of Surveillance Capitalism by Shoshana Zuboff(3946)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3788)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3590)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3566)
