这是2个解决方案.
使用系统属性
boolean isEclipse() {
return System.getProperty("java.class.path").contains("eclipse");
}
Run Code Online (Sandbox Code Playgroud)
使用stacktrace
boolean isEclipse() {
Throwable t = new Throwable();
StackTraceElement[] trace = t.getStackTrace();
return trace[trace.length - 1].getClassName().startsWith("org.eclipse");
}
Run Code Online (Sandbox Code Playgroud)