Consider this example taken from a book, with a super class Gen and a subclass Gen2...
class Gen<T> { }
class Gen2<T> extends Gen<T> { }
Now the book states following will not compile (lets assume its in a main method)
Gen2<Integer> obj = new Gen2<Integer>();
if (obj instanceof Gen2<Integer>) {
//do something
}
This can't be compiled because generic type info does not exist at runtime. If it doesn't exist at runtime, when does it exist? I thought that it would not exist at compile time, but would exist at runtime. Certainly, the following works for runtime with a wildcard...
if (obj instanceof Gen<?>) {
//do something else
}
So, to clarify, my question is: why does generic type information not exist at runtime? Have I overlooked a simple concept?