[英]The method getOrDefault(String, String) is undefined for the type Map<String,String>
in the following code I get an error at the return of the namespaceMap. 在下面的代码中,我在namespaceMap的返回时遇到错误。 Don't know why. 不知道为什么。 getOrDefault Methode should be defined in HashMap.class. getOrDefault Methode应该在HashMap.class中定义。 I tried to create an NamespaceMapper as described in the linked example https://www.intertech.com/Blog/jaxb-tutorial-customized-namespace-prefixes-example-using-namespaceprefixmapper/ 我尝试创建一个NamespaceMapper,如链接示例中所述https://www.intertech.com/Blog/jaxb-tutorial-customized-namespace-prefixes-example-using-namespaceprefixmapper/
import java.util.HashMap;
import java.util.Map;
import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
public class FimsNamespacePrefixMapper extends NamespacePrefixMapper {
private Map<String, String> namespaceMap = new HashMap<>();
public FimsNamespacePrefixMapper() {
namespaceMap.put("http://base.fims.tv", "bms");
namespaceMap.put("http://transformmedia.fims.tv", "tms");
}
@Override
public String getPreferredPrefix(String arg0, String arg1, boolean arg2) {
return namespaceMap.getOrDefault(arg0, arg1);
}}
The getOrDefault
method was introduced in Java 8. Check which runtime version of Java you are using by running java -version
. getOrDefault
方法是在Java 8中引入的。通过运行java -version
来检查您正在使用的Java运行时版本。 If you are using something lower than Java 8 (1.8), upgrade and your code should work. 如果您使用的是低于Java 8(1.8)的内容,则升级并且您的代码应该可以运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.