Top "Generics" questions

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

Cast Object to Generic Type for returning

Is there a way to cast an object to return value of a method? I tried this way but it …

java generics casting
Generic List - moving an item within the list

So I have a generic list, and an oldIndex and a newIndex value. I want to move the item at …

c# .net generics list
What is the best way to clone/deep copy a .NET generic Dictionary<string, T>?

I've got a generic dictionary Dictionary<string, T> that I would like to essentially make a Clone() of ..…

c# generics collections clone
How to convert int[] to Integer[] in Java?

I'm new to Java and very confused. I have a large dataset of length 4 int[] and I want to count …

java arrays generics collections
Instantiating a generic class in Java

I know Java's generics are somewhat inferior to .Net's. I have a generic class Foo<T>, and I …

java generics
Method has the same erasure as another method in type

Why is it not legal to have the following two methods in the same class? class Test{ void add(Set&…

java generics
Get type of a generic parameter in Java with reflection

Is it possible to get the type of a generic parameter? An example: public final class Voodoo { public static void …

java generics reflection
Using Mockito to mock classes with generic parameters

Is there a clean method of mocking a class with generic parameters? Say I have to mock a class Foo&…

java generics mockito
How can I return NULL from a generic method in C#?

I have a generic method with this (dummy) code (yes I'm aware IList has predicates, but my code is not …

c# generics
Java generics - get class?

I got a list, programmed like this: public class MyList<T>. Is there any way to use the …

java generics