In OOP, a covariant return type of a method is one that can be replaced by a "specialized" type when the method is overridden in a subclass. C# does not support return type covariance. Covariant return types have been (partially) allowed in the Java language since the release of JDK5.0, so the following example wouldn't compile on a previous release: // Classes used as return types: class Person { } class Guy extends Person { } // "Class Guy is more specific than class Person" // Classes demonstrating method overriding: class Department { public Person getPerson ( ) { return new Person ( ) ; } } class DepartmentOfGuys extends Department { public Guy getPerson ( ) { return new Guy ( ) ; } } More specifically, covariant (wide to narrower) or contravariant (narrow to wider) return type refers to a situation where the return type of the overriding method ...
The Tech Blog about Information Technology, Programming, the Java Platform, and other Software related topics