【问题标题】:Determine if object is integer确定对象是否为整数
【发布时间】:2012-02-13 04:23:24
【问题描述】:

如何判断Object是否为Integer?比如:

if (obj.isInteger()) {...}

【问题讨论】:

  • 其他方式:if ((Object)(obj).getClass()==Integer.class) {}

标签: java object integer


【解决方案1】:
if (obj instanceof Integer) {....}

【讨论】:

    【解决方案2】:
    if(ob instanceof Integer)
    
    { your code/logic here}
    

    【讨论】:

      【解决方案3】:

      您可以使用 Class.isInstance() 方法 - 此方法是 dynamic 等效于 Java 语言 instanceof 运算符。

      【讨论】:

      • 链接已损坏。我认为将来也会引用更新的文档
      猜你喜欢
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 2014-04-09
      • 2012-05-18
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 2020-08-31
      相关资源
      最近更新 更多