Java PropertyKeyInteger必须设置为字符串。为什么?

Java PropertyKeyInteger必须设置为字符串。为什么?,java,types,properties,nullpointerexception,Java,Types,Properties,Nullpointerexception,我正在测试部分代码,但我发现在java中设置属性的行为很奇怪。我正在为JUnit测试设置一些假属性。问题在于属性PARTNER_ID,它应该是根据定义的整数值,但当我使用method put设置它时,我必须将它设置为String,否则我会得到null指针异常。 代码中的一些重要部分不仅仅是文字: import java.util.Properties; //definition of properties public interface PropertyKeys { public

我正在测试部分代码,但我发现在java中设置属性的行为很奇怪。我正在为JUnit测试设置一些假属性。问题在于属性PARTNER_ID,它应该是根据定义的整数值,但当我使用method put设置它时,我必须将它设置为String,否则我会得到null指针异常。 代码中的一些重要部分不仅仅是文字:

import java.util.Properties;
//definition of properties    
public interface PropertyKeys  {

 public static final PropertyKeyInteger PARTNER_ID = new PropertyKeyInteger(
      "partnerId",null);
}

//fake set of the properties for mock
Properties properties = new Properties();
properties.put("partnerId","102"); //this works
// properties.put("partnerId",102); // this ends with null pointer on PropertyKeys.PARTNER_ID.getProperty(properties)  

//this is how its called in some method
PropertyKeys.PARTNER_ID.getProperty(properties)

问题是:为什么它只允许我将期望的整数值属性设置为字符串,而对于整数,它在空指针异常上使用空指针时失败?

PARTNER\u ID=newpropertykeyinteger==>PropertyKeyInteger是什么?你有密码吗?@user1097772你能发布你的PropertyKeyIntegerClass吗?