my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generic Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generic Doubt" Watch "Generic Doubt" New topic
Author

Generic Doubt

Akhil Maharaj
Ranch Hand

Joined: Sep 29, 2007
Posts: 63
Hi ,

I think I found this line some where in K&B Book . I am not sure however.

But can any of you provide more explanation to these lines .


When you write generic classes � you can use T with wild card �?� . When you write Generic methods � you can not use T with wild card ?
adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186
look at page 604 it gives more detail,
for instanc, my guess

class myGen<T> {
T obj1;
void setObj (T whatever) {}
}


if we declare a class with a wildcard...

class myGen<?> {
? obj1;
}

it doesnt even compile.
adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186
Originally posted by adam lui:
look at page 604 it gives more detail,
for instanc, my guess

class myGen<T> {
T obj1;
void setObj (T whatever) {}
}


if we declare a class with a wildcard...

class myGen<?> {
? obj1;
}

it doesnt even compile.



if we try to add a method
public <? extends T> void myGen1(T something) {}

no, it doesnt compile neither!
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Howdy,

you cannot say "? extends T" because after the "extends" the compiler is wayting for a type, not a generic parameter.
Nitpicking: it would compile however if "T" was a real type of a class with name "T".

Yours,
Bu.


all events occur in real time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generic Doubt