博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于对象与类型
阅读量:6993 次
发布时间:2019-06-27

本文共 715 字,大约阅读时间需要 2 分钟。

 

1 package test; 2  3 public class Square {   4     long width;   5     public Square(long l) {    6         width = l;   7     }   8     public static void main(String arg[]) {    9         Square a, b, c;  10         a = new Square(42L);   11         b = new Square(42L);   12         c = b;   13         long s = 42L;  14         System.out.println(a == b); // false15         //System.out.println(s == a); //Incompatible operand types long and Square16         System.out.println(b == c); // true17         System.out.println(a.equals(s)); // false18     } 19 }

 

在上面的例子中,a与b为Square的实例,为两个不同的对象;

s为基本类型,与对象进行比较时会报错,报错类型:Incompatible operand types long and Square

 

转载于:https://www.cnblogs.com/huanghy/p/10502189.html

你可能感兴趣的文章
DOM和BOM
查看>>
prometheus监控示例
查看>>
细菌的繁殖
查看>>
Windows Server 2008远程连接人数限制修改及修改端口
查看>>
第70天:jQuery基本选择器(一)
查看>>
目前微信 微博 新浪 豆瓣等所有分享的js插件
查看>>
源码包安装
查看>>
处理:“ORA-28002: the password will expire within 7 days”的问题
查看>>
读书笔记—CLR via C#章节4-7
查看>>
linux 命令与文件的查询
查看>>
MYSQL数据库引擎 MYISAM和 INNODB区别
查看>>
设计模式之原型模式
查看>>
BootStrap常用组件及响应式开发
查看>>
TS学习之for..of
查看>>
OpenGL是什么?
查看>>
Oracle - 数据库巡检脚本
查看>>
Oracle 11g数据库详细安装步骤图解
查看>>
机器学习之特征选择---特征选择算法
查看>>
嵌入式开发之hisilicon---hi3536 处理器简介
查看>>
目标跟踪之模板匹配---简单的模板匹配
查看>>