// what to replace XXX with as a return type?"
public XXX getStoreResult() {
HashMap<Object, List<Dashboard>> map = new HashMap<>();
// how to return the map?
}
I have HashMap
defined with key as object and value as Arraylist
of type Dashboard.How to return the map? Also I want to fetch it in servlet and forward it to JSP page? How to do so?
只需在可视性修饰符和方法名称之间的方法定义中添加返回类型:
您可以直接将其返回:
您的样本不值得单独使用。但这是一个很好的例子。尝试开始将功能部分分成使它们可重用的方法。
Notice I used the exact implementation
HashMap
(a class) against its abstract (general) representationMap
(which is an interface). It's correct to "implement against interface".在继续基于Java Facets和JEE的更复杂的解决方案(例如JSP)之前,您必须首先学习Java的基础知识。在Google上可能会找到许多教程,但是正如我所说的-在继续之前先从Java开始。 :)