This is super frustrating. Am I overthinking this challenge? Can someone help?
Here's my code so far.
Wow, I guess I've been overthinking this problem. Thanks both of you for your help.
Special thanks to you, jcorum, for your explanation, when you said "Since Set is an interface you need to pick a particular type of Set"
For Task 2 they want a set, so you need to add an import statement. Since Set is an interface you need to pick a particular type of Set. I use TreeSet here, but they may accept HashSet or LinkedHashSet instead, I didn't try all 3 types.
Finally, you need to return the value from mContactMethods for a given key. The example they give is phone (as the method) and (555) 555-1234 as the value.
That should do it. Good luck and happy programming!
Just a quick question. I noticed when using the TreeSet implementation of the Set interface that you omitted the type, String. Is that allowed? I added the String type in mine and it worked. So just wondering about that.
Hi Kabir - That is a feature introduced in Java 7. In Java 6 and older you have to include the type inside the diamond operator on both sides.
In the addContactMethod() method you need to add the key-value pair passed in to the HashMap mContactsMethod. This HashMap is already created in the constructor so you shouldn't create another one. You basically need to write one line of code that uses a method of the HashMap class to add method and value as a key-value pair to the mContactsMethod.
Ok, got it. Thanks, Kourosh.