Java Java Data Structures Efficiency! Using a Map to store Contact Methods

Julian Garcia
Julian Garcia
18,378 Points

java compiler error

I am trying the second part of the task and I am trying the minimal, no matter if I try:

Set<String> newSet = (Set) mContactMethods.keySet(); 
return newSet;

or just

 return mContactMethods.keySet();

as a text I am trying:

Set<String> hashset = new HashSet<String>();    
    return hashset;

this is the error i get

./com/example/model/Contact.java:48: error: cannot find symbol
    return Set;
           ^
  symbol:   variable Set
  location: class Contact
Note: JavaTester.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

What is wrong?

com/example/model/Contact.java
package com.example.model;

import java.util.Map;
import java.util.Set;
import java.util.HashSet;
import java.util.HashMap;

public class Contact {
  private String mFirstName;
  private String mLastName;
  private Map<String, String> mContactMethods;

  public Contact(String firstName, String lastName) {
    mFirstName = firstName;
    mLastName = lastName;
    /* This stores contact methods by name
     * eg:  "phone" => "(555) 555-1234"
     */
    mContactMethods = new HashMap<String, String>();
  }

  public void addContactMethod(String method, String value) {
    // TODO: Add to the contact method map
    mContactMethods.put(method, value);
  }

  /**
   * Returns the available contact methods.  eg: phone, pager,
   *
   * @return The name of the contact methods that are available
   */
  public Set<String> getAvailableContactMethods() {
    // FIXME: This should return the current contact method names.

    Set<String> hashset = new HashSet<String>();    
    return hashset;
  }

  /**
   * Returns the value for the contact method if it exists, 
   *
   * @param methodName  The name of the contact method to look up.
   * @return The name of the contact methods that are available
   */
  public String getContactInfo(String methodName) {
    // FIXME: return the value for the passed in *methodName*

    return Set;
  }

  public String getFirstName() {
    return mFirstName;
  }

  public String getLastName() {
    return mLastName;
  }

}


./com/example/model/Contact.java:48: error: cannot find symbol
    return Set;
           ^
  symbol:   variable Set
  location: class Contact
Note: JavaTester.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

2 Answers

Simon Coates
Simon Coates
28,654 Points

It doesn't know what you mean by Set

  public String getContactInfo(String methodName) {
    // FIXME: return the value for the passed in *methodName*
    return Set;
  }
Julian Garcia
Julian Garcia
18,378 Points

You were right, It was a typing error.

Thanks.

Simon Coates
Simon Coates
28,654 Points

yeah, when writing java without an IDE, you see the message "cannot find symbol" a lot. It just means java found something it can't interpret. Usually its a spelling mistake, or maybe, a failure to include an import statement.