0
我想編譯這個程序。它適用於2個字符串(姓名,電話號碼),但不適用於3個字符串(姓名,電話號碼和性別)。使用java.util.Map時的編譯問題
CODE(不工作密碼 - 3個字符串(姓名,電話號碼和性別))
import java.util.Map;
import java.util.TreeMap;
public class Ann {
String name, phone;
public Ann() {
}
public static void testMap() {
Map<String, String, String> theMap = new TreeMap<String, String,String>();
// new HashMap<K,V>(); could also be used
theMap.put("Roger M", "090-997-2918", "Male");
theMap.put("Jane M", "090-997-1987", "FeMale");
theMap.put("Stacy K", "090-997-9188", "FeMale");
theMap.put("Gary G", "201-119-8765", "Male");
theMap.put("Jane M", "090-233-0000", "FeMale");
System.out.println("Testing TreeMap and Map");
System.out.print("Stacy K has phone ");
System.out.print(theMap.get("Stacy K"));
System.out.print("\n");
System.out.print("Jane M has phone ");
System.out.print(theMap.get("Jane M"));
} // testMap()
public static void main(String[] args) {
testMap();
}
}
錯誤
wrong number of type arguments; required 2
wrong number of type arguments; required 2
工作代碼(對於2個字符串(姓名,PHONENUMBER))
import java.util.Map;
import java.util.TreeMap;
public class Ann {
String name, phone;
public Ann() {
}
public static void testMap() {
Map<String, String> theMap = new TreeMap<String, String>();
// new HashMap<K,V>(); could also be used
theMap.put("Roger M", "090-997-2918");
theMap.put("Jane M", "090-997-1987");
theMap.put("Stacy K", "090-997-9188");
theMap.put("Gary G", "201-119-8765");
theMap.put("Jane M", "090-233-0000");
System.out.println("Testing TreeMap and Map");
System.out.print("Stacy K has phone ");
System.out.print(theMap.get("Stacy K"));
System.out.print("\n");
System.out.print("Jane M has phone ");
System.out.print(theMap.get("Jane M"));
} // testMap()
public static void main(String[] args) {
testMap();
}
}
我想要的代碼,像名約5屬性工作,電話,性別,年齡,地址。如果有人能夠幫助我編譯問題頂部的代碼,我可以找出其餘的問題。
感謝
當在泛型聲明中放置不正確的對象時,我遇到了此錯誤。它應該是'>',但實際上是>。這令人困惑,因爲編譯器沒有指出該行的正確位置。這是函數簽名中的許多參數之一,編譯器指向該行的開頭。 –
aliteralmind
2014-06-26 15:32:58