How do generics get compiled by the JIT compiler?

I recommend reading Generics in C#, Java, and C++: A Conversation with Anders Hejlsberg. Qn 1. How do generics get compiled by the JIT compiler? From the interview: Anders Hejlsberg: […] In the CLR [Common Language Runtime], when you compile List, or any other generic type, it compiles down to IL [Intermediate Language] and metadata … Read more

Reified generics in Scala 2.10

Your argument is flawed. Kotlin has not been released yet*, and Ceylon just had its first version released, and I’ll quote one of the things it is missing from their announcement: reified generics So, excuse me, but what implementation proves it is possible? In fact, I haven’t looked much at what Kotlin is promising, but … Read more

Java comparing generic types

You cannot overload operators in Java. The < operator only applies to primitive (or numeric) types, not reference types. Since T is a type variable that represents a reference type, you cannot use < on variables of type T. You have to use if (item.compareTo(bn.item) < 0) check the value returned and decide to do … Read more

How to get actual type arguments of a reified generic parameter in Kotlin?

Due to type erasure, actual generic arguments cannot be obtained through T::class token of a generic class. Different objects of a class must have the same class token, that’s why it cannot contain actual generic arguments. Edit: Since Kotlin 1.3.50, following the technique described below to get type information for a reified type parameter is … Read more

What is the use and point of unbound wildcards generics in Java?

An unbound type can be useful when your method doesn’t really care about the actual type. A primitive example would be this: public void printStuff(Iterable<?> stuff) { for (Object item : stuff) { System.out.println(item); } } Since PrintStream.println() can handle all reference types (by calling toString()), we don’t care what the actual content of that … Read more

Unable to get a generic ResponseEntity where T is a generic class “SomeClass”

This was a known issue. Now it’s fixed with the introduction of ParameterizedTypeReference, which is a parameterized type that you explicitely inherit to supply type information at runtime. This is called a super-type token, and works around type erasure because subclasses (anoniymous in this case) keep the type arguments of the generic supertype at runtime. … Read more

Generic List of Generic Interfaces not allowed, any alternative approaches?

public interface IPrimitive { } public interface IPrimitive<T> : IPrimitive { T Value { get; } } public class Star : IPrimitive<T> //must declare T here { } Then you should be able to have List<IPrimitive> primitives = new List<IPrimitive>; primitives.Add(new Star()); // Assuming Star implements IPrimitive primitives.Add(new Sun()); // Assuming Sun implements IPrimitive

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)