我的以下代码给出了错误!在spark.get(新路线(“/”)。我是新手,任何帮助都会引起赞赏吗?任何建议
public static void main(String[] args) {
final Configuration configuration=new Configuration();
configuration.setClassForTemplateLoading(sparkclass.class,"/");
final StringWriter writer=new StringWriter();
Spark.get(new Route("/"){
public Object handle(Request request, Response response) throws Exception {
Template helloTemplate=configuration.getTemplate("hello.ftl");
HashMap<String,Object>mp=new HashMap<String, Object>();
mp.put("name","Sumit");
helloTemplate.process(mp,writer);
System.out.print(writer);
return writer;
}
});
}
答案 0 :(得分:1)
匿名类不能具有显式声明的构造函数。 相反,Java编译器必须自动提供匿名 匿名类的构造函数。
因此你无法通过arg。
参考:http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.9.5.1