Top "Generics" questions

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

Create a List of primitive int?

Is there a way to create a list of primitive int or any primitives in java like following? List<…

java list generics collections
C# generics syntax for multiple type parameter constraints

Possible Duplicate: Generic methods and multiple constraints I need a generic function that has two type constraints, each inheriting from …

c# generics
Nullable type as a generic parameter possible?

I want to do something like this : myYear = record.GetValueOrNull<int?>("myYear"), Notice the nullable type as the …

c# generics
XML Serialize generic list of serializable objects

Can I serialize a generic list of serializable objects without having to specify their type. Something like the intention behind …

c# list generics xml-serialization
Passing arguments to C# generic new() of templated type

I'm trying to create a new object of type T via its constructor when adding to the list. I'm getting …

c# .net generics new-operator
List<T> or IList<T>

Can anyone explain to me why I would want to use IList over List in C#? Related question: Why is …

c# list generics
C#: Printing all properties of an object

Is there a method built in to .NET that can write all the properties and such of an object to …

c# generics console object
Collections.emptyList() returns a List<Object>?

I'm having some trouble navigating Java's rule for inferring generic type parameters. Consider the following class, which has an optional …

java generics type-inference
How to cast List<Object> to List<MyClass>

This does not compile, any suggestion appreciated. ... List<Object> list = getList(); return (List<Customer>) list; Compiler …

java generics casting
How to initialize a List<T> to a given size (as opposed to capacity)?

.NET offers a generic list container whose performance is almost identical (see Performance of Arrays vs. Lists question). However they …

c# .net generics list initialization