如果我有两个班级,一个班级parent
和一个班级child
。
(defclass parent ()
...)
(defclass child (parent)
...)
而且我为initialize-instance定义了2种不同的方法,但是孩子的方法接受了另一个参数,然后调用 call-next-method
(defmethod initialize-instance :after ((instance parent) &key)
...) ; Do things
(defmethod initialize-instance :after ((instance child) &key other-arg)
... ; Do things
(call-next-method))
我得到了错误
There is no next method for the generic function
#<STANDARD-METHOD COMMON-LISP:INITIALIZE-INSTANCE (93)>
when called from method
#<STANDARD-METHOD COMMON-LISP:INITIALIZE-INSTANCE :AFTER (CHILD) {...}>
with arguments
....
Condition of type SB-PCL::NO-NEXT-METHOD-ERROR
显然,我不能使用提供的参数调用下一个方法吗?
在标准方法组合(即你正在使用的方法)中,在方法没有下一个方法之后,因此call-next-method
不能在其中使用:在方法组合全部按最特定-最后的顺序调用所有方法之后才适用。你被允许使用的场所call-next-method
是主要场所和周边场所。