User loginNavigation |
(noob question) method parameters in co-and-contravariance issueIs co- and contravariance a concept related to inheritance or can it apply to normal method parameters ? e.g. In java class Food{} class Grass extends Food {} class Antelope extends Food {} public class Main2 { public static void main(String[] args) { Main2.eat( new Food() ); Main2.eat( new Grass() ); Main2.swallow( new Food() ); // compile-time error Main2.swallow( new Grass() ); } public static void eat( Food f ) {} public static void swallow( Grass f ) {} }
Am I correct in my reasoning ? Thanks By chihiro at 2008-01-30 05:07 | LtU Forum | previous forum topic | next forum topic | other blogs | 5147 reads
|
Browse archives
Active forum topics |
Recent comments
23 weeks 1 day ago
23 weeks 1 day ago
23 weeks 1 day ago
45 weeks 2 days ago
49 weeks 4 days ago
51 weeks 1 day ago
51 weeks 1 day ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago