Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下代码:
trait T { function foo() {} } class C { use T { T::foo as bar; } use T { T::foo as baz; } }
产生以下错误:
trait 方法 bar 没有应用,因为在 C 上和其他 trait 方法有冲突
是否可以在课堂上使用两次特质?
要使用不同的名称多次“导入”在特征中定义的方法,请执行以下操作:
class C { use T { foo as bar; foo as baz; } }
是的,你可以使用一个 trait 两次:
trait T { function foo() {} } class C { use T { T::foo as bar; T::foo as baz; } }