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 | 5171 reads
|
Browse archives
Active forum topics |
Recent comments
32 weeks 6 days ago
32 weeks 6 days ago
32 weeks 6 days ago
1 year 3 weeks ago
1 year 7 weeks ago
1 year 8 weeks ago
1 year 8 weeks ago
1 year 11 weeks ago
1 year 16 weeks ago
1 year 16 weeks ago