不确定标题是否有意义,但我试图从接收到Linkedhashmap的类返回Success消息,但是当我尝试编译文件时,eclipse会给我错误,提供
Remove arguments to match 'logFile()'
Create constructor 'logFile(Map<String, String>)'
如何设置发送Map
并撤消String
?
谢谢
领域
根据以下@Jeff Storey更正的代码,错误抑制为eclipse
调用类
eventLog.put(stringA,stringB);
logFile logStuff = new logFile();
successRtn = logFile.Process(eventLog);
// Do Stuff with SuccessRtn
logFile类
public class logFile {
static String Success = "Fail";
public static String Process(Map<String, String> eventlog){
// Do Stuff
Success = "Yeh!"
return Success;
}
public static void main(String[] args){
@SuppressWarnings("static-access")
String result = new logFile().Procces(eventLog);
System.out.println("result = " + result);
}
答案 0 :(得分:1)
main 方法是一种特殊方法,当用作应用程序的入口点时,其签名必须为public static void main(String[] args)
。创建第二个执行实际工作的方法,如下所示:
public class LogFile {
public String process(Map<String,String> eventLog) {
// do stuff
return success;
}
public void main(String[] args) {
// eventLog will probably be read from a filepath passed into the args
String result = new LogFile().process(eventLog);
System.out.println("result = " + result);
}
}
请注意,许多命名约定也是非标准的。类应以大写字母开头,变量应以小写字母开头。