Programming language is Java.
Why can't we do something like the following? public foo(Consumer consumer) {
Type type = consumer.getGenericTypeParameter();
}
public foo(Consumer consumer) {
Type type = consumer.getGenericTypeParameter();
}
Generic type information is only available to the compiler, not the JVM. In other words, generic type information is not available to the JVM at runtime, only compile time. This is called type erasure.
The above example is a pseudo code equivalent of what things might look like without type erasure , but unfortunately, it is impossible. Once again, the generic type information is not available at runtime.
Get Answers For Free
Most questions answered within 1 hours.