Java 从属性映射中删除条目
我想从属性映射中删除入口。问题是remove方法与我搜索的密钥不匹配:Java 从属性映射中删除条目,java,attributes,Java,Attributes,我想从属性映射中删除入口。问题是remove方法与我搜索的密钥不匹配: final Attributes attributes = manifest.getMainAttributes(); symbolicName = getAttributeValue(attributes, "Bundle-SymbolicName"); attributes.remove("Bundle-SymbolicName"); 当我运行该代码时,带有键“Bundle SymbolicName”(以及我尝试删除的
final Attributes attributes = manifest.getMainAttributes();
symbolicName = getAttributeValue(attributes, "Bundle-SymbolicName");
attributes.remove("Bundle-SymbolicName");
当我运行该代码时,带有键“Bundle SymbolicName”(以及我尝试删除的每一个键)的条目仍然在attributes中
在调试器中,我可以计算以下表达式:
=0.1.0.0attributes.getValue(“捆绑包版本”)
=falseattributes.containsKey(“捆绑版本”)
返回null(返回以前的属性值,如果没有,则返回null。)attributes.remove(“捆绑包版本”)
这是类型转换的问题吗?确实回答了我的问题:
属性的键不是字符串。我需要使用类型Attributes.Name
注意Attributes
的键不是字符串。它们的类型是Attributes.Name
。要添加到Real怀疑论者的注释中,getValue(String)是一个方便的方法:谢谢,这就解释了它。我找不到钥匙的具体类型。