假设A类中有个属性 Map<String ,User> map = new HashMap<String,User>();假设B类中也有个属性Map<String ,User1> map01= new HashMap<String,User1>();我现在要把A类中的map 转换为B中的map01
public Map<String ,User1> getmap(A a){}
// 请教一下 下面的代码该怎么写啊 快点啊 急用 如果用for的话 貌似搞不定.
public Map<String ,User1> getmap(A a){}
// 请教一下 下面的代码该怎么写啊 快点啊 急用 如果用for的话 貌似搞不定.
public Map getMap(){
return map;
}然后在刚才你给的方法体中加入:
return a.getMap();即可.
原理:java中对象传递的是引用。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<input id="hidden_Input" type="hidden" />
<a href="child.htm" target="_blank">Popup Child.htm</a>
<a href="javascript:alert(document.getElementById('hidden_Input').value);">show value</a>
</body>
</html>在Child.htm里的html如下<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function testme()
{
var parent = window.parent.opener;
var hiddenInput = parent.document.getElementById('hidden_Input');
if(hiddenInput)
{
hiddenInput.value = 'show me the money, hahaha';
alert('close this window and see what happens on parent.htm~');
window.close();
}
}
</script>
<title></title>
</head>
<body>
<button onclick="testme();">Click me to set value</button>
</body>
</html>
<div id="Print">
</div>
<script language="javascript" type="text/javascript">
$("#Print").html(self.opener.$("#"+self.opener.$("#printid").val()).html());
</script>
</body>
为什么要转换呢?