Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
wildcard arguments - when can we use
ankur rathi
Ranch Hand
Posts: 3852
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
wildcard arguments ... one example is clear that is in HS ( can be used when a method is taking type parameter )
class My<T extends Number> { void m(My<?> m) { } }
Now we can pass any reference variable of the Number or its sub class in m() method .
public static void main(String[] s) { My<Integer> m = new My<Integer>(); m.m(new Double()); }
But what other situations where wildcard arguments may be useful .
thanks .
[ February 01, 2005: Message edited by: rathi ji ]
Joyce Lee
Ranch Hand
Posts: 1392
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public static void main(String[] s) { My<Integer> m = new My<Integer>(); m.m(new Double()); // better compile to see if this statement is // legal or not. }
ankur rathi
Ranch Hand
Posts: 3852
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Sorry , the code would be like this .
public static void main(String[] s) { My<Integer> m = new My<Integer>(); m.m(new My<Double>()); }
but my doubt remains the same .
please solve .
thanks .
ankur rathi
Ranch Hand
Posts: 3852
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
OK , just tell me this code is right or not .
thanks a lot .
Joyce Lee
Ranch Hand
Posts: 1392
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public static void main(String[] s) { My<Integer> m = new My<Integer>(); m.m(new My<Double>()); }
Yes, this one is correct.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
how this is possible in generic method ...
Generics Lower and Upper Bound
Examlab generics question
Generics - return types
Generics Doubt
More...