This a example code in the book:
abstract class Check {
def check():String = "Checked Application Details... "
}
trait EmploymentCheck extends Check{
override def check():String = "Check Employment ... " + super.check()
}
val app = new Check with EmploymentCheck
Which make me confused is the new Check
, How can we instantiation a abstract class ? And why it will work by with EmploymentCheck
?
new Check with EmploymentCheck
generates an anonymous concrete subclass of Check
. No abstract class is instantiated.
scala> app.getClass
res0: Class[_ <: EmploymentCheck] = class $anon$1
您要实例化的类型是Check with EmploymentCheck
不是Check
,并且Check with EmploymentCheck
不是抽象的,因为抽象成员的check
已经由EmploymentCheck
填写。
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.