java the complete reference 8th edition
page no. 334
topic - Bounded Types
compiler has no way to know that you are intending to create Gen object using only numeric types
Richard Hayward wrote:Assuming you have defined a Dog class, when the compiler compiles the Gen class, how is it supposed to know that you do not intend to do something like this?
Puspender Tanwar wrote:
I have written Gen<Integer> d = new Gen<Integer>(); which perfect for that method , then why the compiler is predicting the case where I can write the incorrect one...why such prediction by compiler even if there is no such incorrect code ???
Henry Wong wrote:
Second, let's take Richard example to an extreme. Let's say you compile and give the generic class bytecode to Richard -- after call, from your argument, the code should compile right? Richard then uses your compiled class, but for his Dog class, then what? Should the compiler somehow go back to tell you that your class won't compile? And if so, how?
Henry
Puspender Tanwar wrote:
so, in short the compiler take care for generic class so that no one can use in incorrectly(In future if someone is using that generic class) by giving compilation error.... right ??
Puspender Tanwar wrote:
at compile time, the Type Parameter <T> is unknown or the Object type ??
Puspender Tanwar wrote:hello marco,
I don't think so
Consider Paul's rocket mass heater. |