Top "Generics" questions

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

When do Java generics require <? extends T> instead of <T> and is there any downside of switching?

Given the following example (using JUnit with Hamcrest matchers): Map<String, Class<? extends Serializable>> expected = null; …

java generics junit
Google Gson - deserialize list<class> object? (generic type)

I want to transfer a list object via Google Gson, but I don't know how to deserialize generic types. What …

java json generics gson
Get generic type of java.util.List

I have; List<String> stringList = new ArrayList<String>(); List<Integer> integerList = new ArrayList<…

java generics
How to update an object in a List<> in C#

I have a List<> of custom objects. I need to find an object in this list by some …

c# asp.net list generics
C# Syntax - Split String into Array by Comma, Convert To Generic List, and Reverse Order

What is the correct syntax for this: IList<string> names = "Tom,Scott,Bob".Split(',').ToList<…

c# generics syntax ilist
How do I make the return type of a method generic?

Is there a way to make this method generic so I can return a string, bool, int, or double? Right …

c# .net generics return-type
How do you cast a List of supertypes to a List of subtypes?

For example, lets say you have two classes: public class TestA {} public class TestB extends TestA{} I have a method …

java list generics collections casting
Creating a generic method in C#

I am trying to combine a bunch of similar methods into a generic method. I have several methods that return …

c# generics
How do I use reflection to call a generic method?

What's the best way to call a generic method when the type parameter isn't known at compile time, but instead …

c# .net generics reflection
The given key was not present in the dictionary. Which key?

Is there a way to get the value of the given key in the following exception in C# in a …

c# exception generics dictionary