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
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Programmer Certification (OCPJP)
Generics
Nikhil Jain
Ranch Hand
Posts: 393
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
package st; import java.util.HashMap; public class UseGenerics { public static void main(String[] args) { HashMap<String, Object> returnValue = null; Generics generics = new Generics(); returnValue = (HashMap<String, Object> :wink: generics.getAttribute(); } } package st; public class Generics { public Object getAttribute() { return "" //Returns something like hashMap } }
Eclipse gives a warning for the above code.
Type safety: The cast from Object to HashMap<
String
,Object> is actually checking against the erased type HashMap
How will we return something of object type in generics without getting the warning ...
SCJP 1.4, SCWCD 1.4, SCBCD 1.5, TOGAF 9, Comptia Cloud+
Kaydell Leavitt
Ranch Hand
Posts: 694
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm not sure why, but I believe that you need to replace <String, Object> with <String, ?>
Bras cause cancer. And tiny ads:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
generics
Generics
Generics
Generics
More...