Top "Generics" questions

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

How do I find out what type each object is in a ArrayList<Object>?

I have a ArrayList made up of different elements imported from a db, made up of strings, numbers, doubles and …

java generics reflection arraylist
Convert string to List<string> in one line?

I have a string: var names = "Brian,Joe,Chris"; Is there a way to convert this to a List<…

c# asp.net list generics string
How do I clone a generic List in Java?

I have an ArrayList<String> that I'd like to return a copy of. ArrayList has a clone method …

java generics arraylist clone
Difference between <? super T> and <? extends T> in Java

What is the difference between List<? super T> and List<? extends T> ? I used to use …

java generics collections
convert a list of objects from one type to another using lambda expression

I have a foreach loop reading a list of objects of one type and producing a list of objects of …

c# generics lambda
java: HashMap<String, int> not working

HashMap<String, int> doesn't seem to work but HashMap<String, Integer> does work. Any ideas why?

java generics
What is a raw type and why shouldn't we use it?

Questions: What are raw types in Java, and why do I often hear that they shouldn't be used in new …

java generics raw-types
foreach vs someList.ForEach(){}

There are apparently many ways to iterate over a collection. Curious if there are any differences, or why you'd use …

c# .net generics loops enumeration
Create instance of generic type whose constructor requires a parameter?

If BaseFruit has a constructor that accepts an int weight, can I instantiate a piece of fruit in a generic …

c# .net generics
Convert DataTable to List<T>

I have an strongly typed DataTable of type MyType, I'd like convert it in a List<MyType>. How …

c# .net generics datatable