[英]What does Map<String, Serializable> mean?
有人可以解釋一下Map<String, Serializable>
是什么意思嗎? 我知道Map必須有鍵值對,我習慣看<String, String>
<Integer, whatever>
,但我從未見過Serializable
類型的值。 我也明白Serializable
是一個在磁盤/網絡上將對象寫入字節的過程。 但是當我們使用Map<String, Serializable>
時,這一切是如何加起來的? 它歸結為什么?
我可以將任何對象放入Serializable類型的值中,或者它必須是某個特殊對象或其他東西嗎? 有人能解開一些光嗎?
我也明白
Serializable
是一個在磁盤/網絡上將對象寫入字節的過程。 但是當我們使用Map<String, Serializable>
時,這一切是如何加起來的?
Serializable
是一個Java接口:
FROM API
:
java.io.Serializable
接口的類啟用了類的可序列化。 我可以將任何對象放入
Serializable
類型的值中,或者它必須是某個特殊對象或其他東西嗎?
有人可以解釋一下
Map<String, Serializable>
是什么意思嗎?
這意味着您將擁有一個String
鍵和一個必須是實現Serializable
的對象的值。
例如:
// valid object for the map
class Bar implements Serializable {
private static final long serialVersionUID = 1L;
// class stuff
}
// not a candidate
class Foo {
// class stuff
}
然后:
Map<String, Serializable> myMap = new HashMap<String, Serializable>();
Bar bar = new Bar();
map.put("BAR", bar); // this is ok
Foo foo = new Foo();
map.put("FOO", foo);
// The method put(String, Serializable) in the type HashMap<String,Serializable>
// is not applicable for the arguments (String, Foo)
String是鍵,Serializable是值。 它是一個可以在整個集群中序列化和傳輸的對象(使用給定的SerDe)。
Serializable
是一個接口。
這意味着map的值是實現Serializable
接口的類
它還意味着get()方法返回的obgect的靜態類型將是可序列化的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.