我花了3天的时间来查看这个,我找不到一个可靠的答案.我想捕获调试消息,然后将它们输出到列表日志.我想用C#做这个.希望社区的一些帮助指出我正确的方向.
我测试了单例模式的实现,我觉得我无法弄清楚为什么IntelliJ会给我一个错误.这是代码.
public class CowSingleton {
private static CowSingleton unique;
private CowSingleton(){}
//Only create new object if NOT already instantiated.
public static CowSingleton getInstance(){
if (unique == null){
//creating unique object
unique = new CowSingleton();
System.out.println(unique);
}
//return Object
return unique;
}
public String cowMoo(String str)
{
return str;
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我如何称呼它:
CowSingleton cowSingleton = new CowSingleton.getInstance();
System.out.println(cowSingleton.cowMoo("Moooooo"));
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
"java: /Users/gpendleton/Personal/MyAnimals/src/Main.java:25: cannot find symbol
symbol : class getInstance
location: class CowSingleton"
Run Code Online (Sandbox Code Playgroud)