如何在 bean class 中存储 int 和 string 值?

How to store int and string value in bean class?

我知道这是一个非常基本的问题,但我无法得到完美的答案。我有一个名为 Order 的 bean,其中有一个对象 product_size 例如

public Class Order{
      private String product_size;
} 

Setter和Getter方法分别定义在那个class中。问题是 product_size 可能包含 string variable 例如 SInteger value 例如 7.

我无法在该 bean 对象中存储整数值。

我只处理了一个 bean 实例,我正在检查如果值是字符串,它应该添加到 bean 对象中,否则 Integer.toString() 方法会将 int 值转换为 String。

例子如下-

String str;      // it is dynamic let there are two values in this 'S' and 8
if (str instancof String){
   order.setProduct_Size(str);
}else{
  order.setProduct_Size(Integer.toString(str));
}