Skip to Main Content

Java APIs

After compiling classes with generics, can types still be params?

843793Jul 30 2002 — edited Jul 31 2002


As I understand it, generics types are a feature of the compiler, not the compiled class. So if I compile some classes (containing parameterized types/generics), the compiler helps check type safety. But once they're compiled, if generics really are just "a compiler features", in any other Java code that I write that refers to the compiled classes, it seems perfectly possible that I could refer to methods in the compiled class using inappropriate casts/types, because the generic information is present in the source code, and no longer present in the compiled class.

This seems to be a big limitation, as it would mean I'd lose the benefits of generics when working with the core API or compiled classes (especially likely with JAR files...). I must be missing something here, anyone able to help me understand how parameterized types can be used when referring to compiled classes (for which I don't have access to the source code) from my own Java code?

Chris B.
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 28 2002
Added on Jul 30 2002