| Author |
Generics question
|
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
|
Hi, This is general question. what if I do 300 will be printed at Line # 5 ?
|
OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
|
 |
Trivikram Kamat
Ranch Hand
Joined: Sep 26, 2010
Posts: 155
|
|
|
I don't understand the use of Generic type T in class Processor, if you're confident of typecasting parameters of type T (of method addAll) to Integer type.
|
OCPJP6
|
 |
Harikrishna Gorrepati
Ranch Hand
Joined: Sep 23, 2010
Posts: 422
|
|
Trivikram Kamat wrote:I don't understand the use of Generic type T in class Processor, if you're confident of typecasting parameters of type T (of method addAll) to Integer type.
I can print 300 in Processor class. But I want 300 to be returned to the caller at Line #4 and print at Line # 5
|
 |
Trivikram Kamat
Ranch Hand
Joined: Sep 26, 2010
Posts: 155
|
|
The meaning of my question was, if you're sure that you can typecast T to Integer in method addAll(), then I don't think there's need of forceful use of Generics in this case.
A generic type is a reference type that defines a list of formal type parameters or type variables that must be provided before it can be used as a type.
So, you don't know what type T will be while defining class Processor.
I guess it would be inappropriate to use typecasting T to Integer.
|
 |
 |
|
|
subject: Generics question
|
|
|