Long l1 = null;
Long l2 = Long.getLong("23");
Long l3 = Long.valueOf(23);
System.out.println(l1 instanceof Long); // returns false
System.out.println(l2 instanceof Long); // returns false
System.out.println(l3 instanceof Long); // returns true
我无法理解返回的输出。我期待 true atleast 对于 2nd 和 3rd syso's。谁能解释一下 instanceof 是如何工作的?
最佳答案
这与instanceof
无关。 Long.getLong()
方法不解析字符串,它返回具有该名称的系统属性的内容,解释为 long。由于没有名称为 23 的系统属性,因此它返回 null。你想要 Long.parseLong()
关于java - 关于 instanceof 工作的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2153953/