简体   繁体   中英

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. Don't know why. getOrDefault Methode should be defined in 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/

 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 . If you are using something lower than Java 8 (1.8), upgrade and your code should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM