Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
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:
Beginning Java
The Diamond
meeta gaur
Ranch Hand
Posts: 305
I like...
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
interface Pair<K,V> { K getKey(); V getValue(); } class Colour<T>{} class OrderedPair<K,V> implements Pair<K,V> { private K k; private V v; OrderedPair(K k,V v){ this.k=k; this.v=v; } public K getKey(){ return k; } public V getValue(){ return v; } public static void main(String[] args) { Pair<String,Integer> obj1=new OrderedPair<>("k1",13); System.out.println(obj1.getKey()+" = "+obj1.getValue()); Pair<String,String> obj2=new OrderedPair<>("k2","hello"); System.out.println(obj2.getKey()+" = "+obj2.getValue()); Pair<String,Colour<String>> obj3=new OrderedPair<>("k3",new Colour<>()); } }
OrderedPair.java:32: error: incompatible types
Pair<
String
,Colour<String>> obj3=new OrderedPair<>("k3",new Colour<>());
^
required: Pair<String,Colour<String>>
found: OrderedPair<String,Colour<Object>>
1 error
Why diamond isn't working for Colour?
My one regret in life is that I am not someone else.
- Woody Allen
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Inheriting variable and static functions
Inner classes & Static blocks
inner class/inheritance
question concering hashCode(), equals() and operator ==
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
More...