Top "Generics" questions

Generics are a form of parametric polymorphism found in a range of languages, including .NET languages, Java, Swift, and Rust.

How can I use interface as a C# generic type constraint?

Is there a way to get the following function declaration? public bool Foo<T>() where T : interface; ie. …

c# generics interface constraints
Case insensitive access for generic dictionary

I have an application that use managed dlls. One of those dlls return a generic dictionary: Dictionary<string, int&…

c# generics dictionary
How to create a generic array?

I don't understand the connection between generics and arrays. I can create array reference with generic type: private E[] elements; //…

java generics
Is there a constraint that restricts my generic method to numeric types?

Can anyone tell me if there is a way with generics to limit a generic type argument T to only: …

c# generics constraints
List<Map<String, String>> vs List<? extends Map<String, String>>

Is there any difference between List<Map<String, String>> and List<? extends Map<String, …

java generics inheritance polymorphism
Can't operator == be applied to generic types in C#?

According to the documentation of the == operator in MSDN, For predefined value types, the equality operator (==) returns true if the …

c# generics operators equals-operator
Is List<Dog> a subclass of List<Animal>? Why are Java generics not implicitly polymorphic?

I'm a bit confused about how Java generics handle inheritance / polymorphism. Assume the following hierarchy - Animal (Parent) Dog - …

java generics inheritance polymorphism
C# Determine Duplicate in List

Requirement: In an unsorted List, determine if a duplicate exists. The typical way I would do this is an n-squared …

c# linq algorithm list generics
What is PECS (Producer Extends Consumer Super)?

I came across PECS (short for Producer extends and Consumer super) while reading up on generics. Can someone explain to …

java generics super bounded-wildcard pecs
Possible heap pollution via varargs parameter

I understand this occurs with Java 7 when using varargs with a generic type; But my question is.. What exactly does …

java eclipse generics variadic-functions