Top "Generics" questions

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

Jackson - Deserialize using generic class

I have a json string, which I should deSerialize to the following class class Data <T> { int found; …

java json generics jackson
Java: Instanceof and Generics

Before I look through my generic data structure for a value's index, I'd like to see if it is even …

java generics instanceof typechecking
Performance of Arrays vs. Lists

Say you need to have a list/array of integers which you need iterate frequently, and I mean extremely often. …

.net performance arrays generics list
Java generics - why is "extends T" allowed but not "implements T"?

I wonder if there is a special reason in Java for using always "extends" rather than "implements" for defining bounds …

java generics syntax design-choices
What's the reason I can't create generic array types in Java?

What's the reason why Java doesn't allow us to do private T[] elements = new T[initialCapacity]; I could understand .NET …

java generics type-erasure
How to have Java method return generic list of any type?

I would like to write a method that would return a java.util.List of any type without the need …

java list generics reflection casting
Java Class.cast() vs. cast operator

Having being taught during my C++ days about evils of the C-style cast operator I was pleased at first to …

java generics casting compiler-warnings
How to dynamically create generic C# object using reflection?

In C# I have the following object: public class Item { } public class Task<T> { } public class TaskA<…

c# generics reflection activator
Static method in a generic class?

In Java, I'd like to have something as: class Clazz<T> { static void doIt(T object) { // ... } } But I …

java generics static-methods
Java: how do I get a class literal from a generic type?

Typically, I've seen people use the class literal like this: Class<Foo> cls = Foo.class; But what if …

java generics class literals