我需要做一些像_.assign这样的事情,但前提是目标对象已经分配了属性.可以想象它就像源对象可能有一些属性要贡献,但也有一些我不想混入的属性.
我没有使用_.assign的回调机制,但尝试了以下内容.它"工作",但它仍然将属性分配给dest对象(未定义).我根本不希望它分配.
_.assign(options, defaults, initial, function (destVal, sourceVal) {
return typeof destVal == 'undefined' ? undefined : sourceVal;
});
Run Code Online (Sandbox Code Playgroud)
我写了以下函数来做到这一点,但想知道lodash是否已经有更多优雅的东西.
function softMerge (dest, source) {
return Object.keys(dest).reduce(function (dest, key) {
var sourceVal = source[key];
if (!_.isUndefined(sourceVal)) {
dest[key] = sourceVal;
}
return dest;
}, dest);
}
Run Code Online (Sandbox Code Playgroud) 在 Java 11 下运行 Eclipse 时,使用google-java-format eclipse 插件效果很好,但在 Java 16+ 上运行时,它会失败并出现以下错误:
完整错误:A save participant caused problems. The save participant 'Code Clean Up' caused an exception: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.JavaInput (in unnamed module @0x99c5646) cannot access class com.sun.tools.javac.parser.Tokens$TokenKind (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.parser to unnamed module @0x99c5646. See the error log for details.
google-java-formatter确实注意到--add-exports,在 JDK 16+ 上运行时,由于 JEP-396(JDK 内部的强封装),您需要在运行格式化程序时设置标志。不清楚的是如何判断--add-exportsEclipse 插件的设置。
添加以下内容eclipse.ini(或在我的情况下SpringToolSuite4.ini)似乎没有帮助(更不用说它感觉不对,因为它不针对该特定插件)。有没有不同的方法来处理/解决这个问题?
-vmargs
-Dosgi.requiredJavaVersion=11
-Dosgi.dataAreaRequiresExplicitInit=true
-Xms256m
-Xmx2048m …Run Code Online (Sandbox Code Playgroud) eclipse eclipse-plugin spring-tool-suite google-java-format java-16