JAVA报错:The operator != is undefined for the argument type(s) int,null

来源:百度知道 编辑:UC知道 时间:2024/06/16 00:26:24
if(formbean.getParentid()!= null && formbean.getParentid()>0)
type.setParent(new ProductType(formbean.getParentid()));

这个表达式里面为什么会报错啊:The operator != is undefined for the argument type(s) int,null 把null改成1就可以了 我的跟老师的代码一样啊,为什么我的会报错呢
formbean.getParentid()!= null 是这句报错的

null只是对对象有用,基本类型没有null。

package cn.edu.shu.web.test;

public class TestInteger {

public static void main(String[] args) {

/**

* 问题来源是在Struts2的action中,如果从session中取值,如果取不到的话,那么应该为null,由于我将其强转为Integer类型了,其后再将其与Integer比较时,居然抛空指针异常

*/

Object one = null;

Integer two = (Integer) one;

System.out.println(null == two);// out put true

System.out.println(two instanceof Integer);// out put false

System.out.println(two instanceof Object);// out put false

// System.out.println(0 == two);// 抛出空指针异常

// 思索,由于JDK有自动拆装箱操作,所以即使用的是Integer,其也会被拆箱为int类型,这样在使用操作符时,不满足int型和null型比较

// 编译错误: The operator == is undefined for the argument type(s) int, null

System.out.println(0 == null);

}

}

java 报什么错 这个JAVA报错是什么意思? java运行报错!!急 The machine is operated by an attending operator . java报错高手来看看 Java 简单 关于printf报错 JAVA连接SQL server2000报错 jsp进行运算时出现operator *cannot be applied to java.lang.Float的问题 附加10分,翻译Available exclusively to subscribers of operator Three across the globe. Mechanically held torches with increasedprotection for the operator怎么翻译啊?