1 interface I { I clone(); } 2 interface J { J clone(); } 3 class C : I 4 { 5 override C clone() // covariant overriding of I.clone() 6 { 7 return new C; 8 } 9 } 10 11 // C.clone() can override I.clone(), indeed. 12 static assert(isCovariantWith!(typeof(C.clone), typeof(I.clone))); 13 14 // C.clone() can't override J.clone(); the return type C is not implicitly 15 // convertible to J. 16 static assert(!isCovariantWith!(typeof(C.clone), typeof(J.clone)));
Determines whether the function type F is covariant with G, i.e., functions of the type F can override ones of the type G.