September 2015
Intermediate to advanced
250 pages
6h 40m
English
When working with a large library you may come across a class name that simply does not work for you. The name is either long or unwieldy, or you simply feel there is a better name that captures the abstraction. You have the freedom to alias, and give the class the name that will make you feel good.
Here’s a class with a rather long name:
| WorkingWithObjects/PoliceOfficer.scala | |
| | class PoliceOfficer(val name: String) |
Cop says it all and is easier to type as well. Here’s how we can alias the PoliceOfficer class without losing its identity:
| WorkingWithObjects/CopApp.scala | |
| | object CopApp extends App { |
| | type Cop = PoliceOfficer |
| | |
| | val topCop = new Cop("Jack") |
| | println(topCop.getClass) |
| | } |
Compile and run the code to ...
Read now
Unlock full access