Can a JIT take a benefit from Generics?

Viewed 214

It is well known, that generic types don't survive the compiling process. They are replaced by class casts.

But nevertheless, the type information is present in the class file and can be seen using reflection:

public class Demo
{
    private List<String> list;

    public Demo() throws SecurityException, NoSuchFieldException
    {
        System.out.println(((Class<?>)((ParameterizedType) getClass().getDeclaredField("list").getGenericType()).getActualTypeArguments()[0]).getName());
    }

    public static void main(String[] args) throws SecurityException, NoSuchFieldException
    {
        new Demo();
    }
}

When executed, this will print java.lang.String.

Can a JIT use this for some kind of optimization? Or is that information from the point of view of the JIT useless?

2 Answers
Related