Groovy equals()方法
该方法确定调用方法的Number对象是否等于作为参数传递的对象。
句法
public boolean equals(Object o)
参数
o - 任何对象。
返回值
如果参数不为空,并且是同一类型且具有相同数值的对象,则方法返回True。
例子
下面是一个使用这个方法的例子 -
class Example { static void main(String[] args) { Integer x = 5; Integer y = 10; Integer z = 5; //Comparison against an Integer of different value System.out.println(x.equals(y)); //Comparison against an Integer of same value System.out.println(x.equals(z)); } }
当我们运行上面的程序,我们将得到以下结果 -
false true