Top "Generics" questions

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

How to Sort a List<T> by a property in the object

I have a class called Order which has properties such as OrderId, OrderDate, Quantity, and Total. I have a list …

c# generics list sorting
How to create a generic array in Java?

Due to the implementation of Java generics, you can't have code like this: public class GenSet<E> { private …

java arrays generics reflection instantiation
How do I get a class instance of generic type T?

I have a generics class, Foo<T>. In a method of Foo, I want to get the class …

java generics
How do I make the method return type generic?

Consider this example (typical in OOP books): I have an Animal class, where each Animal can have many friends. And …

java generics return-value
List<T> OrderBy Alphabetical Order

I'm using C# on Framework 3.5. I'm looking to quickly sort a Generic List<T>. For the sake of …

c# generics list lambda sorting
How to get the type of T from a member of a generic class or method?

Let say I have a generic member in a class or method, so: public class Foo<T> { public …

c# .net generics
How do I clone a generic list in C#?

I have a generic list of objects in C#, and wish to clone the list. The items within the list …

c# generics list clone
Get generic type of class at runtime

How can I achieve this? public class GenericClass<T> { public Type getMyType() { //How do I return the type …

java generics reflection
Remove duplicates from a List<T> in C#

Anyone have a quick method for de-duplicating a generic List in C#?

c# list generics duplicates
How to use Class<T> in Java?

There's a good discussion of Generics and what they really do behind the scenes over at this question, so we …

java templates class generics