contravariance Questions

5

Solved

I will start by saying that I am Java developer learning to program in C#. As such I do comparisons of what I know with what I am learning. I have been playing with C# generics for a few hours no...
Collocate asked 21/3, 2012 at 14:2

2

Solved

Could you please explain using small and simple TypeScript examples what is Variance, Covariance, Contravariance, Bivariance and Invariance?

2

Solved

Assume I have interface and class: public interface ITree {} public class Tree : ITree {} As IEnumerable<T> is covariant, the code line below is compiled successfully: IEnumerable<ITre...
Grassplot asked 5/10, 2012 at 9:32

5

Solved

I have a struct that has inner mutability. use std::cell::RefCell; struct MutableInterior { hide_me: i32, vec: Vec<i32>, } struct Foo { //although not used in this particular snippet, /...

6

I am working on a ASP.NET Core 2.2 Web API application with Mediatr. I have a handler that looks like - public class MyQueryHandler<T> : IRequestHanlder<MyQuery<T>, IQueryable<...
Audiometer asked 15/8, 2019 at 2:57

1

Solved

I have a function that expects a short lived object. I would expect that I would be able to always pass it a long lived object. But I am getting a strange error when I try to encode that: type F&lt...
Hydrokinetic asked 18/8, 2022 at 19:8

5

Solved

Given the followin snippet, i quite dont understand WHY what im going to achieve is not possible: Interface: public interface IEntityRepository<out T> : IRepository<IEntity> { void ...
Paver asked 1/7, 2016 at 7:52

1

Solved

C++20 allows the program to specify concept for template template argument. For example, #include <concepts> template <typename T> concept Char = std::same_as<T, char>; template ...
Lidstone asked 2/8, 2021 at 13:22

6

Solved

I am having trouble understanding the difference between covariance and contravariance.
Drypoint asked 2/2, 2010 at 14:7

2

Solved

Consider the contravariant interface definition with a delegate: public interface IInterface<in TInput> { delegate int Foo(int x); void Bar(TInput input); void Baz(TInput input, Foo fo...

0

The following code demonstrates it clearly: trait Poly1Group[-IUB, +OUB] { trait Case[-I <: IUB] { type Out <: OUB // <------------------------------- success def apply(v: I): Out ...
Recoup asked 28/1, 2021 at 20:20

3

Solved

Consider the following code: public class Main { static class Animal {} static class Dog extends Animal {} static List<? extends Animal> foo() { List<Dog> dogs = new ArrayList&lt...
Hatter asked 4/8, 2020 at 8:31

4

Solved

Can anyone explain the concept of covariance and contravariance in programming language theory?
Prohibitive asked 22/7, 2009 at 6:49

1

Solved

I want to write a TypeScript method decorator that can only be applied to methods with a certain type of first argument. It's a common pattern in the codebase I'm working in to pass around a reques...
Pah asked 30/1, 2020 at 18:33

5

Solved

I believe one can define covariance (at least, for objects) as 'the ability to use a value of a narrower (sub) type in place of a value of some wider (super) type', and that contravariance is the e...
Heir asked 15/5, 2012 at 15:27

3

Solved

Today, I read some articles about Covariance, Contravariance (and Invariance) in Java. I read the English and German Wikipedia article, and some other blog posts and articles from IBM. But I'm sti...
Insectile asked 12/12, 2011 at 21:44

2

Solved

I never truly understood generics in Java, so it seems to be the case with Kotlin. Consider the following code snippet (it's a contrived example): class AnyComparator: Comparator<Any> { ove...
Swearingen asked 1/7, 2017 at 14:18

2

public class Flea : Animals {...} var fleas = new Dictionary<int, Flea>(); public IReadOnlyDictionary<string, Animal> Animals => fleas.ToDictionary(pair => pair.Key, pair => ...
Billingsley asked 14/6, 2019 at 7:33

1

Solved

In the Nomicon's section about subtyping, it says contravariance is available for a function pointer type. However, I can't find any good examples of this. I tried to code a struct with a function ...
Ronnaronnholm asked 25/3, 2019 at 19:9

1

Solved

In Eric Lippert's blog posts about covariance and contravariance or variance for short, and in books such as C# in a Nutshell, it is stated that : If you’re defining a generic delegate type, it...
Shillong asked 28/2, 2019 at 15:56

1

Solved

When learning more about the standard event model in .NET, I found that before introducing generics in C#, the method that will handle an event is represented by this delegate type: // // Summary:...
Eviaevict asked 27/2, 2019 at 14:3

2

Solved

I can't understand why the following C# code doesn't compile. As you can see, I have a static generic method Something with an IEnumerable<T> parameter (and T is constrained to be an IA inte...
Circumpolar asked 7/11, 2018 at 8:30

7

Solved

The C# spec states that an argument type cannot be both covariant and contravariant at the same time. This is apparent when creating a covariant or contravariant interface you decorate your type p...
Fillip asked 24/12, 2010 at 20:22

3

Solved

One of the rules that Liskov Substitution Principle imposes on method signature in derived class is: Contravariance of method arguments in the subtype. If I understood correctly, it is saying ...
Preemie asked 31/10, 2016 at 10:24

4

Solved

What does the statement mean? From here ref and out parameters in C# and cannot be marked as variant. 1) Does it mean that the following can not be done. public class SomeClass<R, A>:...
Hennessey asked 20/5, 2010 at 17:33

© 2022 - 2025 — McMap. All rights reserved.