Background
My understanding of Java generics is it being completely a compile time feature (mainly focusing on type safety checks)
Is there any information related to generic types which is preserved at runtime as well. ? If yes, what ?.
Single information preserved in the compiled class, are casts from raw objects/variables gotten after erasure to the specific types used as generic in the source code.
But these rely just on the declared type of variable, not the real generic type used.
So, at runtime you cannot directly access to the generic information without workaround as passing a class when you instantiate a generic class.
If no, than how does libraries like google guice operate internally (
You are wrong.
In Guice this code :
Content content = contentProvider.get();
will return an instance of Content
, not the generic type.
Look at the documentation :
T get()
Provides an instance of T.