面向对象核心概念
面向对象与面向过程编程的差异
面向过程编程(POP):将问题分解为一系列步骤(函数),通过函数调用解决问题。
面向对象编程(OOP):将问题抽象为对象,通过对象间的协作解决问题。
// 面向过程:计算圆的属性
public class ProcedureDemo {
public static void main(String[] args) {
double radius = 5.0;
double area = 3.14 * radius * radius;
double circumference = 2 * 3.14 * radius;
System.out.println("面积:" + area);
System.out.println("周长:" + circumference);
}
}
// 面向对象:计算圆的属性
public class Circle {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
public double getArea() {
return Math.PI * radius * radius;
}
public double getCircumference() {
return 2 * Math.PI * radius;
}
public static void main(String[] args) {
Circle circle = new Circle(5.0);
System.out.println("面积:" + circle.getArea());
System.out.println("周长:" + circle.getCircumference());
}
}
OOP 的优势:
- 易维护:良好的封装性,修改局部不影响整体
- 易复用:通过继承实现代码复用
- 易扩展:多态机制使系统扩展灵活
性能对比是常见误区:两种范式的性能差异主要取决于具体实现,而非范式本身。现代语言通常同时支持两种范式。
对象的创建与引用
使用 new 运算符创建对象:
Student stu = new Student("张三", 20);
对象实体 vs 对象引用:
-
对象实体:存储在堆内存中的实际数据
-
对象引用:存储在栈内存中的地址
Student s1 = new Student("张三", 20); // s1 指向对象 A Student s2 = s1; // s2 也指向对象 A Student s3 = new Student("张三", 20); // s3 指向新对象 B
System.out.println(s1 == s2); // true (引用相等) System.out.println(s1 == s3); // false (引用不等)
类比:对象像气球,引用像绳子
- 一条绳子可以不系气球(null)
- 一条绳子只能系一个气球
- 多条绳子可以系同一个气球
### 对象相等 vs 引用相等
String str1 = "Java"; String str2 = new String("Java"); String str3 = "Java";
// 引用相等:比较内存地址 System.out.println(str1 == str2); // false (不同对象) System.out.println(str1 == str3); // true (字符串常量池)
// 对象相等:比较内容 System.out.println(str1.equals(str2)); // true System.out.println(str1.equals(str3)); // true
**规则**:
- 基本类型用 `==` 比较值
- 引用类型用 `==` 比较地址,用 `equals()` 比较内容
### 构造方法详解
如果类没有声明构造方法,编译器会自动添加无参构造方法:
```java
public class Product {
private String name;
// 编译器自动添加
// public Product() { }
}
// 可以正常使用
Product p = new Product();
重要提示:一旦手动定义了任何构造方法,编译器就不再提供默认构造方法:
public class Product {
private String name;
public Product(String name) {
this.name = name;
}
}
// Product p = new Product(); // 编译错误:找不到无参构造
Product p = new Product("手机"); // 正确
最佳实践:即使不用,也建议保留无参构造方法
public class Product {
private String name;
// 显式定义无参构造
public Product() { }
public Product(String name) {
this.name = name;
}
}
构造方法特点:
- 方法名与类名完全相同
- 没有返回值类型(连 void 也不写)
- 对象创建时自动调用
- 可以重载,不能重写
- 不能被 static/final/abstract 修饰
面向对象三大特征
1. 封装(Encapsulation)
将对象的状态隐藏,只对外暴露必要的接口:
public class BankAccount {
private double balance; // 隐藏余额
public double getBalance() {
return balance;
}
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
}
}
public boolean withdraw(double amount) {
if (amount > 0 && balance >= amount) {
balance -= amount;
return true;
}
return false;
}
}
好处:
- 隐藏实现细节
- 提高安全性
- 便于修改实现
2. 继承(Inheritance)
子类继承父类的属性和方法,实现代码复用:
class Employee {
protected String name;
protected double salary;
public Employee(String name, double salary) {
this.name = name;
this.salary = salary;
}
public void work() {
System.out.println(name + " 正在工作");
}
}
class Programmer extends Employee {
private String language;
public Programmer(String name, double salary, String language) {
super(name, salary); // 调用父类构造方法
this.language = language;
}
@Override
public void work() {
System.out.println(name + " 正在用 " + language + " 编程");
}
public void debug() {
System.out.println(name + " 正在调试代码");
}
}
继承要点:
- 子类拥有父类所有属性和方法(包括 private,但无法直接访问)
- 子类可以扩展新的属性和方法
- 子类可以重写父类的方法
3. 多态(Polymorphism)
同一个行为具有多种不同表现形式:
class Animal {
public void makeSound() {
System.out.println("动物发出声音");
}
}
class Dog extends Animal {
@Override
public void makeSound() {
System.out.println("汪汪汪");
}
}
class Cat extends Animal {
@Override
public void makeSound() {
System.out.println("喵喵喵");
}
}
public class PolymorphismDemo {
public static void main(String[] args) {
Animal animal1 = new Dog(); // 向上转型
Animal animal2 = new Cat();
animal1.makeSound(); // 输出:汪汪汪
animal2.makeSound(); // 输出:喵喵喵
// 多态性:同样的方法调用,不同的执行结果
}
}
多态的必要条件:
- 存在继承关系
- 子类重写父类方法
- 父类引用指向子类对象
多态的特点:
- 编译时类型与运行时类型可以不一致
- 调用哪个方法在运行时确定
- 不能调用子类特有的方法
接口与抽象类对比
共同点
- 都不能直接实例化
- 都可以包含抽象方法
- 都用于抽象和解耦
核心差异
| 特性 | 接口(Interface) | 抽象类(Abstract Class) |
| 设计目的 | 定义行为规范 | 提供通用实现 |
| 继承/实现 | 类可实现多个接口 | 类只能继承一个抽象类 |
| 成员变量 | 只能是 public static final | 可以有任意修饰符 |
| 方法 | Java 8+ 可有 default/static 方法 | 可有抽象和非抽象方法 |
| 构造方法 | 不能有 | 可以有 |
// 接口:定义飞行能力
interface Flyable {
void fly();
default void land() { // Java 8+ 默认方法
System.out.println("降落");
}
}
// 抽象类:定义鸟的通用特征
abstract class Bird {
protected String name;
public Bird(String name) {
this.name = name;
}
// 抽象方法
public abstract void eat();
// 具体方法
public void sleep() {
System.out.println(name + " 正在睡觉");
}
}
// 既继承抽象类,又实现接口
class Eagle extends Bird implements Flyable {
public Eagle(String name) {
super(name);
}
@Override
public void eat() {
System.out.println(name + " 吃肉");
}
@Override
public void fly() {
System.out.println(name + " 在天空翱翔");
}
}
使用场景:
- 接口:定义规范,如 Serializable, Comparable
- 抽象类:提供基础实现,如 InputStream, HttpServlet
深拷贝与浅拷贝
引用拷贝
两个引用指向同一对象:
Person p1 = new Person("张三", 20);
Person p2 = p1; // 引用拷贝
p2.setAge(25);
System.out.println(p1.getAge()); // 25 (p1 也变了)
浅拷贝
创建新对象,但内部引用类型属性共享:
class Address {
String city;
public Address(String city) { this.city = city; }
}
class Person implements Cloneable {
String name;
Address address;
public Person(String name, Address address) {
this.name = name;
this.address = address;
}
@Override
protected Person clone() throws CloneNotSupportedException {
return (Person) super.clone();
}
}
// 测试
Person p1 = new Person("张三", new Address("北京"));
Person p2 = p1.clone();
System.out.println(p1 == p2); // false (不同对象)
System.out.println(p1.address == p2.address); // true (地址对象共享)
p2.address.city = "上海";
System.out.println(p1.address.city); // 上海 (p1 的地址也变了)
深拷贝
完全复制所有对象,包括引用类型属性:
class Address implements Cloneable {
String city;
public Address(String city) { this.city = city; }
@Override
protected Address clone() throws CloneNotSupportedException {
return (Address) super.clone();
}
}
class Person implements Cloneable {
String name;
Address address;
@Override
protected Person clone() throws CloneNotSupportedException {
Person person = (Person) super.clone();
person.address = address.clone(); // 深拷贝地址
return person;
}
}
// 测试
Person p1 = new Person("张三", new Address("北京"));
Person p2 = p1.clone();
System.out.println(p1.address == p2.address); // false (地址对象独立)
p2.address.city = "上海";
System.out.println(p1.address.city); // 北京 (p1 不受影响)
三者对比图:
%3B%7D%23svg%20.cluster%20rect%7Bfill%3A%23ffffde%3Bstroke%3A%23aaaa33%3Bstroke-width%3A1px%3B%7D%23svg%20.cluster%20text%7Bfill%3A%23333%3B%7D%23svg%20.cluster%20span%2C%23svg%20p%7Bcolor%3A%23333%3B%7D%23svg%20div.mermaidTooltip%7Bposition%3Aabsolute%3Btext-align%3Acenter%3Bmax-width%3A200px%3Bpadding%3A2px%3Bfont-family%3A%22trebuchet%20ms%22%2Cverdana%2Carial%2Csans-serif%3Bfont-size%3A12px%3Bbackground%3Ahsl(80%2C%20100%25%2C%2096.2745098039%25)%3Bborder%3A1px%20solid%20%23aaaa33%3Bborder-radius%3A2px%3Bpointer-events%3Anone%3Bz-index%3A100%3B%7D%23svg%20.flowchartTitleText%7Btext-anchor%3Amiddle%3Bfont-size%3A18px%3Bfill%3A%23333%3B%7D%23svg%20.today%7Bdisplay%3Anone%3B%7D%23svg%20.label%20foreignObject%7Boverflow%3Avisible%3B%7D%23svg%20%3Aroot%7B--mermaid-font-family%3A%22trebuchet%20ms%22%2Cverdana%2Carial%2Csans-serif%3B%7D%23svg%20.refStyle%26gt%3B*%7Bfill%3A%23E85D75!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.refStyle%20span%7Bfill%3A%23E85D75!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.refStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%23svg%20.shallowStyle%26gt%3B*%7Bfill%3A%23E67E22!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.shallowStyle%20span%7Bfill%3A%23E67E22!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.shallowStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%23svg%20.deepStyle%26gt%3B*%7Bfill%3A%2350C878!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.deepStyle%20span%7Bfill%3A%2350C878!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.deepStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%3C%2Fstyle%3E%3Cg%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2212%22%20markerWidth%3D%2212%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%226%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-pointEnd%22%3E%3Cpath%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%200%200%20L%2010%205%20L%200%2010%20z%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2212%22%20markerWidth%3D%2212%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%224.5%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-pointStart%22%3E%3Cpath%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%200%205%20L%2010%2010%20L%2010%200%20z%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%2211%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-circleEnd%22%3E%3Ccircle%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20r%3D%225%22%20cy%3D%225%22%20cx%3D%225%22%3E%3C%2Fcircle%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%22-1%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-circleStart%22%3E%3Ccircle%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20r%3D%225%22%20cy%3D%225%22%20cx%3D%225%22%3E%3C%2Fcircle%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225.2%22%20refX%3D%2212%22%20viewBox%3D%220%200%2011%2011%22%20class%3D%22marker%20cross%20flowchart%22%20id%3D%22svg_flowchart-crossEnd%22%3E%3Cpath%20style%3D%22stroke-width%3A%202%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%201%2C1%20l%209%2C9%20M%2010%2C1%20l%20-9%2C9%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225.2%22%20refX%3D%22-1%22%20viewBox%3D%220%200%2011%2011%22%20class%3D%22marker%20cross%20flowchart%22%20id%3D%22svg_flowchart-crossStart%22%3E%3Cpath%20style%3D%22stroke-width%3A%202%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%201%2C1%20l%209%2C9%20M%2010%2C1%20l%20-9%2C9%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cg%20class%3D%22root%22%3E%3Cg%20class%3D%22clusters%22%3E%3C%2Fg%3E%3Cg%20class%3D%22edgePaths%22%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabels%22%3E%3C%2Fg%3E%3Cg%20class%3D%22nodes%22%3E%3Cg%20transform%3D%22translate(-7.5%2C%20-8)%22%20class%3D%22root%22%3E%3Cg%20class%3D%22clusters%22%3E%3Cg%20id%3D%22%E6%B7%B1%E6%8B%B7%E8%B4%9D%22%20class%3D%22cluster%20default%20flowchart-label%22%3E%3Crect%20height%3D%22192%22%20width%3D%22668%22%20y%3D%228%22%20x%3D%228%22%20ry%3D%220%22%20rx%3D%220%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(318%2C%208)%22%20class%3D%22cluster-label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2248%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E6%B7%B1%E6%8B%B7%E8%B4%9D%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgePaths%22%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-C1%20LE-C1Addr%22%20id%3D%22L-C1-C1Addr-0%22%20d%3D%22M146.233%2C122L157.86%2C126.167C169.488%2C130.333%2C192.744%2C138.667%2C215.989%2C142.833C239.233%2C147%2C262.467%2C147%2C274.083%2C147L285.7%2C147%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-C2%20LE-C2Addr%22%20id%3D%22L-C2-C2Addr-0%22%20d%3D%22M439%2C61L445.833%2C61C452.667%2C61%2C466.333%2C61%2C482.619%2C64.835C498.906%2C68.669%2C517.811%2C76.338%2C527.264%2C80.173L536.717%2C84.008%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3Bstroke-width%3A2px%3Bstroke-dasharray%3A3%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-dotted%20flowchart-link%20LS-C1%20LE-C2%22%20id%3D%22L-C1-C2-0%22%20d%3D%22M146.233%2C86L157.86%2C81.833C169.488%2C77.667%2C192.744%2C69.333%2C212.989%2C65.167C233.233%2C61%2C250.467%2C61%2C259.083%2C61L267.7%2C61%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3Bstroke-width%3A2px%3Bstroke-dasharray%3A3%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-dotted%20flowchart-link%20LS-C1Addr%20LE-C2Addr%22%20id%3D%22L-C1Addr-C2Addr-0%22%20d%3D%22M421%2C147L430.833%2C147C440.667%2C147%2C460.333%2C147%2C479.619%2C143.165C498.906%2C139.331%2C517.811%2C131.662%2C527.264%2C127.827L536.717%2C123.992%22%3E%3C%2Fpath%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabels%22%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(216%2C%2061)%22%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(-32%2C%20-10.5)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2264%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%E5%AE%8C%E5%85%A8%E5%A4%8D%E5%88%B6%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(480%2C%20147)%22%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(-16%2C%20-10.5)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2232%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%E5%A4%8D%E5%88%B6%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22nodes%22%3E%3Cg%20transform%3D%22translate(356%2C%20147)%22%20data-id%3D%22C1Addr%22%20data-node%3D%22true%22%20id%3D%22flowchart-C1Addr-11%22%20class%3D%22node%20default%20deepStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22130%22%20y%3D%22-18%22%20x%3D%22-65%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-53%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22106%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3EAddress%E5%AF%B9%E8%B1%A11%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(96%2C%20104)%22%20data-id%3D%22C1%22%20data-node%3D%22true%22%20id%3D%22flowchart-C1-10%22%20class%3D%22node%20default%20deepStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22126%22%20y%3D%22-18%22%20x%3D%22-63%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-51%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22102%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E5%AF%B9%E8%B1%A1%20person1%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(356%2C%2061)%22%20data-id%3D%22C2%22%20data-node%3D%22true%22%20id%3D%22flowchart-C2-12%22%20class%3D%22node%20default%20deepStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22166%22%20y%3D%22-18%22%20x%3D%22-83%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-71%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22142%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E5%AF%B9%E8%B1%A1%20person1Copy%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(586%2C%20104)%22%20data-id%3D%22C2Addr%22%20data-node%3D%22true%22%20id%3D%22flowchart-C2Addr-13%22%20class%3D%22node%20default%20deepStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22130%22%20y%3D%22-18%22%20x%3D%22-65%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-53%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22106%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3EAddress%E5%AF%B9%E8%B1%A12%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(710.5%2C%2016.75)%22%20class%3D%22root%22%3E%3Cg%20class%3D%22clusters%22%3E%3Cg%20id%3D%22%E6%B5%85%E6%8B%B7%E8%B4%9D%22%20class%3D%22cluster%20default%20flowchart-label%22%3E%3Crect%20height%3D%22142.5%22%20width%3D%22594%22%20y%3D%228%22%20x%3D%228%22%20ry%3D%220%22%20rx%3D%220%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(281%2C%208)%22%20class%3D%22cluster-label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2248%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E6%B5%85%E6%8B%B7%E8%B4%9D%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgePaths%22%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-B1%20LE-B1Addr%22%20id%3D%22L-B1-B1Addr-0%22%20d%3D%22M159%2C54.947L165.833%2C53.206C172.667%2C51.465%2C186.333%2C47.982%2C213.833%2C46.241C241.333%2C44.5%2C282.667%2C44.5%2C321.333%2C44.5C360%2C44.5%2C396%2C44.5%2C417.701%2C45.654C439.401%2C46.808%2C446.803%2C49.115%2C450.504%2C50.269L454.204%2C51.423%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-B2%20LE-B1Addr%22%20id%3D%22L-B2-B1Addr-0%22%20d%3D%22M407%2C97.5L411.167%2C97.5C415.333%2C97.5%2C423.667%2C97.5%2C431.534%2C96.346C439.401%2C95.192%2C446.803%2C92.885%2C450.504%2C91.731L454.204%2C90.577%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3Bstroke-width%3A2px%3Bstroke-dasharray%3A3%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-dotted%20flowchart-link%20LS-B1%20LE-B2%22%20id%3D%22L-B1-B2-0%22%20d%3D%22M159%2C87.053L165.833%2C88.794C172.667%2C90.535%2C186.333%2C94.018%2C199.117%2C95.759C211.9%2C97.5%2C223.8%2C97.5%2C229.75%2C97.5L235.7%2C97.5%22%3E%3C%2Fpath%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabels%22%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(200%2C%2097.5)%22%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(-16%2C%20-10.5)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2232%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%E5%A4%8D%E5%88%B6%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22nodes%22%3E%3Cg%20transform%3D%22translate(517%2C%2071)%22%20data-id%3D%22B1Addr%22%20data-node%3D%22true%22%20id%3D%22flowchart-B1Addr-5%22%20class%3D%22node%20default%20shallowStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22120%22%20y%3D%22-18%22%20x%3D%22-60%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-48%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2296%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3EAddress%E5%AF%B9%E8%B1%A1%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(96%2C%2071)%22%20data-id%3D%22B1%22%20data-node%3D%22true%22%20id%3D%22flowchart-B1-4%22%20class%3D%22node%20default%20shallowStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22126%22%20y%3D%22-18%22%20x%3D%22-63%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-51%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22102%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E5%AF%B9%E8%B1%A1%20person1%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(324%2C%2097.5)%22%20data-id%3D%22B2%22%20data-node%3D%22true%22%20id%3D%22flowchart-B2-6%22%20class%3D%22node%20default%20shallowStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22166%22%20y%3D%22-18%22%20x%3D%22-83%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-71%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22142%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E5%AF%B9%E8%B1%A1%20person1Copy%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(1354.5%2C%20-8)%22%20class%3D%22root%22%3E%3Cg%20class%3D%22clusters%22%3E%3Cg%20id%3D%22%E5%BC%95%E7%94%A8%E6%8B%B7%E8%B4%9D%22%20class%3D%22cluster%20default%20flowchart-label%22%3E%3Crect%20height%3D%22192%22%20width%3D%22301%22%20y%3D%228%22%20x%3D%228%22%20ry%3D%220%22%20rx%3D%220%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(126.5%2C%208)%22%20class%3D%22cluster-label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2264%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E5%BC%95%E7%94%A8%E6%8B%B7%E8%B4%9D%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgePaths%22%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-A1%20LE-Obj1%22%20id%3D%22L-A1-Obj1-0%22%20d%3D%22M146%2C61L150.167%2C61C154.333%2C61%2C162.667%2C61%2C172.77%2C64.699C182.873%2C68.399%2C194.745%2C75.798%2C200.682%2C79.497L206.618%2C83.197%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-A2%20LE-Obj1%22%20id%3D%22L-A2-Obj1-0%22%20d%3D%22M146%2C147L150.167%2C147C154.333%2C147%2C162.667%2C147%2C172.77%2C143.301C182.873%2C139.601%2C194.745%2C132.202%2C200.682%2C128.503L206.618%2C124.803%22%3E%3C%2Fpath%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabels%22%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22nodes%22%3E%3Cg%20transform%3D%22translate(240%2C%20104)%22%20data-id%3D%22Obj1%22%20data-node%3D%22true%22%20id%3D%22flowchart-Obj1-1%22%20class%3D%22node%20default%20refStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%2288%22%20y%3D%22-18%22%20x%3D%22-44%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-32%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2264%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E5%AF%B9%E8%B1%A1%E5%AE%9E%E4%BE%8B%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(89.5%2C%2061)%22%20data-id%3D%22A1%22%20data-node%3D%22true%22%20id%3D%22flowchart-A1-0%22%20class%3D%22node%20default%20refStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22113%22%20y%3D%22-18%22%20x%3D%22-56.5%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-44.5%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2289%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E5%AF%B9%E8%B1%A1%E5%BC%95%E7%94%A8%20p1%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(89.5%2C%20147)%22%20data-id%3D%22A2%22%20data-node%3D%22true%22%20id%3D%22flowchart-A2-2%22%20class%3D%22node%20default%20refStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22113%22%20y%3D%22-18%22%20x%3D%22-56.5%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-44.5%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2289%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E5%AF%B9%E8%B1%A1%E5%BC%95%E7%94%A8%20p2%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E)
Object 类核心方法
Object 类核心方法
Object 是所有类的父类,提供 11 个基础方法:
%3B%7D%23svg%20.cluster%20rect%7Bfill%3A%23ffffde%3Bstroke%3A%23aaaa33%3Bstroke-width%3A1px%3B%7D%23svg%20.cluster%20text%7Bfill%3A%23333%3B%7D%23svg%20.cluster%20span%2C%23svg%20p%7Bcolor%3A%23333%3B%7D%23svg%20div.mermaidTooltip%7Bposition%3Aabsolute%3Btext-align%3Acenter%3Bmax-width%3A200px%3Bpadding%3A2px%3Bfont-family%3A%22trebuchet%20ms%22%2Cverdana%2Carial%2Csans-serif%3Bfont-size%3A12px%3Bbackground%3Ahsl(80%2C%20100%25%2C%2096.2745098039%25)%3Bborder%3A1px%20solid%20%23aaaa33%3Bborder-radius%3A2px%3Bpointer-events%3Anone%3Bz-index%3A100%3B%7D%23svg%20.flowchartTitleText%7Btext-anchor%3Amiddle%3Bfont-size%3A18px%3Bfill%3A%23333%3B%7D%23svg%20.today%7Bdisplay%3Anone%3B%7D%23svg%20.label%20foreignObject%7Boverflow%3Avisible%3B%7D%23svg%20%3Aroot%7B--mermaid-font-family%3A%22trebuchet%20ms%22%2Cverdana%2Carial%2Csans-serif%3B%7D%23svg%20.objectStyle%26gt%3B*%7Bfill%3A%234A90E2!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.objectStyle%20span%7Bfill%3A%234A90E2!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.objectStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%23svg%20.hashStyle%26gt%3B*%7Bfill%3A%23E85D75!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.hashStyle%20span%7Bfill%3A%23E85D75!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.hashStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%23svg%20.compareStyle%26gt%3B*%7Bfill%3A%239B59B6!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.compareStyle%20span%7Bfill%3A%239B59B6!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.compareStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%23svg%20.otherStyle%26gt%3B*%7Bfill%3A%2395A5A6!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.otherStyle%20span%7Bfill%3A%2395A5A6!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.otherStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%3C%2Fstyle%3E%3Cg%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2212%22%20markerWidth%3D%2212%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%226%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-pointEnd%22%3E%3Cpath%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%200%200%20L%2010%205%20L%200%2010%20z%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2212%22%20markerWidth%3D%2212%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%224.5%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-pointStart%22%3E%3Cpath%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%200%205%20L%2010%2010%20L%2010%200%20z%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%2211%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-circleEnd%22%3E%3Ccircle%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20r%3D%225%22%20cy%3D%225%22%20cx%3D%225%22%3E%3C%2Fcircle%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%22-1%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-circleStart%22%3E%3Ccircle%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20r%3D%225%22%20cy%3D%225%22%20cx%3D%225%22%3E%3C%2Fcircle%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225.2%22%20refX%3D%2212%22%20viewBox%3D%220%200%2011%2011%22%20class%3D%22marker%20cross%20flowchart%22%20id%3D%22svg_flowchart-crossEnd%22%3E%3Cpath%20style%3D%22stroke-width%3A%202%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%201%2C1%20l%209%2C9%20M%2010%2C1%20l%20-9%2C9%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225.2%22%20refX%3D%22-1%22%20viewBox%3D%220%200%2011%2011%22%20class%3D%22marker%20cross%20flowchart%22%20id%3D%22svg_flowchart-crossStart%22%3E%3Cpath%20style%3D%22stroke-width%3A%202%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%201%2C1%20l%209%2C9%20M%2010%2C1%20l%20-9%2C9%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cg%20class%3D%22root%22%3E%3Cg%20class%3D%22clusters%22%3E%3C%2Fg%3E%3Cg%20class%3D%22edgePaths%22%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Object%20LE-GetClass%22%20id%3D%22L-Object-GetClass-0%22%20d%3D%22M672.875%2C21.204L572.458%2C27.836C472.042%2C34.469%2C271.208%2C47.735%2C170.792%2C57.651C70.375%2C67.567%2C70.375%2C74.133%2C70.375%2C77.417L70.375%2C80.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Object%20LE-HashCode%22%20id%3D%22L-Object-HashCode-0%22%20d%3D%22M672.875%2C22.379L601.583%2C28.816C530.292%2C35.253%2C387.708%2C48.126%2C316.417%2C57.847C245.125%2C67.567%2C245.125%2C74.133%2C245.125%2C77.417L245.125%2C80.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Object%20LE-Equals%22%20id%3D%22L-Object-Equals-0%22%20d%3D%22M672.875%2C24.738L629.375%2C30.782C585.875%2C36.826%2C498.875%2C48.913%2C455.375%2C58.24C411.875%2C67.567%2C411.875%2C74.133%2C411.875%2C77.417L411.875%2C80.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Object%20LE-Clone%22%20id%3D%22L-Object-Clone-0%22%20d%3D%22M672.875%2C31.834L655.833%2C36.695C638.792%2C41.556%2C604.708%2C51.278%2C587.667%2C59.422C570.625%2C67.567%2C570.625%2C74.133%2C570.625%2C77.417L570.625%2C80.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Object%20LE-ToString%22%20id%3D%22L-Object-ToString-0%22%20d%3D%22M721.375%2C36L721.375%2C40.167C721.375%2C44.333%2C721.375%2C52.667%2C721.375%2C60.117C721.375%2C67.567%2C721.375%2C74.133%2C721.375%2C77.417L721.375%2C80.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Object%20LE-Notify%22%20id%3D%22L-Object-Notify-0%22%20d%3D%22M769.875%2C30.507L789.583%2C35.589C809.292%2C40.671%2C848.708%2C50.836%2C868.417%2C59.201C888.125%2C67.567%2C888.125%2C74.133%2C888.125%2C77.417L888.125%2C80.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Object%20LE-NotifyAll%22%20id%3D%22L-Object-NotifyAll-0%22%20d%3D%22M769.875%2C24.107L818.708%2C30.256C867.542%2C36.405%2C965.208%2C48.702%2C1014.042%2C58.134C1062.875%2C67.567%2C1062.875%2C74.133%2C1062.875%2C77.417L1062.875%2C80.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Object%20LE-Wait%22%20id%3D%22L-Object-Wait-0%22%20d%3D%22M769.875%2C22.169L845.167%2C28.641C920.458%2C35.113%2C1071.042%2C48.056%2C1146.333%2C57.811C1221.625%2C67.567%2C1221.625%2C74.133%2C1221.625%2C77.417L1221.625%2C80.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Object%20LE-Finalize%22%20id%3D%22L-Object-Finalize-0%22%20d%3D%22M769.875%2C21.127L872.958%2C27.772C976.042%2C34.418%2C1182.208%2C47.709%2C1285.292%2C57.638C1388.375%2C67.567%2C1388.375%2C74.133%2C1388.375%2C77.417L1388.375%2C80.7%22%3E%3C%2Fpath%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabels%22%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22nodes%22%3E%3Cg%20transform%3D%22translate(721.375%2C%2018)%22%20data-id%3D%22Object%22%20data-node%3D%22true%22%20id%3D%22flowchart-Object-0%22%20class%3D%22node%20default%20objectStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%2297%22%20y%3D%22-18%22%20x%3D%22-48.5%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-36.5%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2273%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3EObject%20%E7%B1%BB%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(70.375%2C%20113.5)%22%20data-id%3D%22GetClass%22%20data-node%3D%22true%22%20id%3D%22flowchart-GetClass-2%22%20class%3D%22node%20default%20otherStyle%20flowchart-label%22%3E%3Crect%20height%3D%2255%22%20width%3D%22140.75%22%20y%3D%22-27.5%22%20x%3D%22-70.375%22%20ry%3D%2227.5%22%20rx%3D%2227.5%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-56%2C%20-20)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2240%22%20width%3D%22112%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3EgetClass%3Cbr%2F%3E%E8%8E%B7%E5%8F%96%E8%BF%90%E8%A1%8C%E6%97%B6%E7%B1%BB%E5%9E%8B%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(245.125%2C%20113.5)%22%20data-id%3D%22HashCode%22%20data-node%3D%22true%22%20id%3D%22flowchart-HashCode-4%22%20class%3D%22node%20default%20hashStyle%20flowchart-label%22%3E%3Crect%20height%3D%2255%22%20width%3D%22108.75%22%20y%3D%22-27.5%22%20x%3D%22-54.375%22%20ry%3D%2227.5%22%20rx%3D%2227.5%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-40%2C%20-20)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2240%22%20width%3D%2280%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3EhashCode%3Cbr%2F%3E%E8%AE%A1%E7%AE%97%E5%93%88%E5%B8%8C%E7%A0%81%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(411.875%2C%20113.5)%22%20data-id%3D%22Equals%22%20data-node%3D%22true%22%20id%3D%22flowchart-Equals-6%22%20class%3D%22node%20default%20hashStyle%20flowchart-label%22%3E%3Crect%20height%3D%2255%22%20width%3D%22124.75%22%20y%3D%22-27.5%22%20x%3D%22-62.375%22%20ry%3D%2227.5%22%20rx%3D%2227.5%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-48%2C%20-20)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2240%22%20width%3D%2296%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3Eequals%3Cbr%2F%3E%E5%AF%B9%E8%B1%A1%E7%9B%B8%E7%AD%89%E6%AF%94%E8%BE%83%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(570.625%2C%20113.5)%22%20data-id%3D%22Clone%22%20data-node%3D%22true%22%20id%3D%22flowchart-Clone-8%22%20class%3D%22node%20default%20compareStyle%20flowchart-label%22%3E%3Crect%20height%3D%2255%22%20width%3D%2292.75%22%20y%3D%22-27.5%22%20x%3D%22-46.375%22%20ry%3D%2227.5%22%20rx%3D%2227.5%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-32%2C%20-20)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2240%22%20width%3D%2264%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3Eclone%3Cbr%2F%3E%E5%AF%B9%E8%B1%A1%E5%85%8B%E9%9A%86%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(721.375%2C%20113.5)%22%20data-id%3D%22ToString%22%20data-node%3D%22true%22%20id%3D%22flowchart-ToString-10%22%20class%3D%22node%20default%20compareStyle%20flowchart-label%22%3E%3Crect%20height%3D%2255%22%20width%3D%22108.75%22%20y%3D%22-27.5%22%20x%3D%22-54.375%22%20ry%3D%2227.5%22%20rx%3D%2227.5%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-40%2C%20-20)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2240%22%20width%3D%2280%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3EtoString%3Cbr%2F%3E%E5%AD%97%E7%AC%A6%E4%B8%B2%E8%A1%A8%E7%A4%BA%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(888.125%2C%20113.5)%22%20data-id%3D%22Notify%22%20data-node%3D%22true%22%20id%3D%22flowchart-Notify-12%22%20class%3D%22node%20default%20otherStyle%20flowchart-label%22%3E%3Crect%20height%3D%2255%22%20width%3D%22124.75%22%20y%3D%22-27.5%22%20x%3D%22-62.375%22%20ry%3D%2227.5%22%20rx%3D%2227.5%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-48%2C%20-20)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2240%22%20width%3D%2296%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3Enotify%3Cbr%2F%3E%E5%94%A4%E9%86%92%E5%8D%95%E4%B8%AA%E7%BA%BF%E7%A8%8B%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(1062.875%2C%20113.5)%22%20data-id%3D%22NotifyAll%22%20data-node%3D%22true%22%20id%3D%22flowchart-NotifyAll-14%22%20class%3D%22node%20default%20otherStyle%20flowchart-label%22%3E%3Crect%20height%3D%2255%22%20width%3D%22124.75%22%20y%3D%22-27.5%22%20x%3D%22-62.375%22%20ry%3D%2227.5%22%20rx%3D%2227.5%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-48%2C%20-20)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2240%22%20width%3D%2296%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3EnotifyAll%3Cbr%2F%3E%E5%94%A4%E9%86%92%E6%89%80%E6%9C%89%E7%BA%BF%E7%A8%8B%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(1221.625%2C%20113.5)%22%20data-id%3D%22Wait%22%20data-node%3D%22true%22%20id%3D%22flowchart-Wait-16%22%20class%3D%22node%20default%20otherStyle%20flowchart-label%22%3E%3Crect%20height%3D%2255%22%20width%3D%2292.75%22%20y%3D%22-27.5%22%20x%3D%22-46.375%22%20ry%3D%2227.5%22%20rx%3D%2227.5%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-32%2C%20-20)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2240%22%20width%3D%2264%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3Ewait%3Cbr%2F%3E%E7%BA%BF%E7%A8%8B%E7%AD%89%E5%BE%85%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(1388.375%2C%20113.5)%22%20data-id%3D%22Finalize%22%20data-node%3D%22true%22%20id%3D%22flowchart-Finalize-18%22%20class%3D%22node%20default%20otherStyle%20flowchart-label%22%3E%3Crect%20height%3D%2255%22%20width%3D%22140.75%22%20y%3D%22-27.5%22%20x%3D%22-70.375%22%20ry%3D%2227.5%22%20rx%3D%2227.5%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-56%2C%20-20)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2240%22%20width%3D%22112%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3Efinalize%3Cbr%2F%3E%E5%AF%B9%E8%B1%A1%E9%94%80%E6%AF%81%E5%89%8D%E5%9B%9E%E8%B0%83%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E)
// 1. 获取运行时类型
public final native Class<?> getClass()
// 2. 计算哈希码
public native int hashCode()
// 3. 对象相等性比较
public boolean equals(Object obj)
// 4. 对象克隆
protected native Object clone() throws CloneNotSupportedException
// 5. 对象的字符串表示
public String toString()
// 6. 唤醒单个等待线程
public final native void notify()
// 7. 唤醒所有等待线程
public final native void notifyAll()
// 8. 线程等待
public final native void wait(long timeout) throws InterruptedException
public final void wait(long timeout, int nanos) throws InterruptedException
public final void wait() throws InterruptedException
// 9. 对象销毁前回调
protected void finalize() throws Throwable
== 与 equals() 的区别
== 的行为:
-
基本类型:比较值
-
引用类型:比较内存地址
int a = 100; int b = 100; System.out.println(a == b); // true (值相等) Integer x = 100; Integer y = 100; System.out.println(x == y); // true (缓存池内) Integer m = 1000; Integer n = 1000; System.out.println(m == n); // false (超出缓存)
equals() 的行为:
Object 类的默认实现:
public boolean equals(Object obj) {
return (this == obj); // 默认比较引用
}
String 类的重写实现:
public boolean equals(Object anObject) {
if (this == anObject) return true;
if (anObject instanceof String) {
String anotherString = (String) anObject;
int n = value.length;
if (n == anotherString.value.length) {
char v1[] = value;
char v2[] = anotherString.value;
int i = 0;
while (n-- != 0) {
if (v1[i] != v2[i]) return false;
i++;
}
return true;
}
}
return false;
}
hashCode() 的作用
hashCode() 返回对象的哈希码,用于哈希表中快速定位对象。
HashSet 添加元素流程:
%3B%7D%23svg%20.cluster%20rect%7Bfill%3A%23ffffde%3Bstroke%3A%23aaaa33%3Bstroke-width%3A1px%3B%7D%23svg%20.cluster%20text%7Bfill%3A%23333%3B%7D%23svg%20.cluster%20span%2C%23svg%20p%7Bcolor%3A%23333%3B%7D%23svg%20div.mermaidTooltip%7Bposition%3Aabsolute%3Btext-align%3Acenter%3Bmax-width%3A200px%3Bpadding%3A2px%3Bfont-family%3A%22trebuchet%20ms%22%2Cverdana%2Carial%2Csans-serif%3Bfont-size%3A12px%3Bbackground%3Ahsl(80%2C%20100%25%2C%2096.2745098039%25)%3Bborder%3A1px%20solid%20%23aaaa33%3Bborder-radius%3A2px%3Bpointer-events%3Anone%3Bz-index%3A100%3B%7D%23svg%20.flowchartTitleText%7Btext-anchor%3Amiddle%3Bfont-size%3A18px%3Bfill%3A%23333%3B%7D%23svg%20.today%7Bdisplay%3Anone%3B%7D%23svg%20.label%20foreignObject%7Boverflow%3Avisible%3B%7D%23svg%20%3Aroot%7B--mermaid-font-family%3A%22trebuchet%20ms%22%2Cverdana%2Carial%2Csans-serif%3B%7D%23svg%20.processStyle%26gt%3B*%7Bfill%3A%234A90E2!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.processStyle%20span%7Bfill%3A%234A90E2!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.processStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%23svg%20.decisionStyle%26gt%3B*%7Bfill%3A%239B59B6!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.decisionStyle%20span%7Bfill%3A%239B59B6!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.decisionStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%23svg%20.successStyle%26gt%3B*%7Bfill%3A%2350C878!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.successStyle%20span%7Bfill%3A%2350C878!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.successStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%23svg%20.failStyle%26gt%3B*%7Bfill%3A%23E85D75!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.failStyle%20span%7Bfill%3A%23E85D75!important%3Bstroke%3Anone!important%3Bcolor%3A%23fff!important%3B%7D%23svg%20.failStyle%20tspan%7Bfill%3A%23fff!important%3B%7D%3C%2Fstyle%3E%3Cg%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2212%22%20markerWidth%3D%2212%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%226%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-pointEnd%22%3E%3Cpath%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%200%200%20L%2010%205%20L%200%2010%20z%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2212%22%20markerWidth%3D%2212%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%224.5%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-pointStart%22%3E%3Cpath%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%200%205%20L%2010%2010%20L%2010%200%20z%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%2211%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-circleEnd%22%3E%3Ccircle%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20r%3D%225%22%20cy%3D%225%22%20cx%3D%225%22%3E%3C%2Fcircle%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225%22%20refX%3D%22-1%22%20viewBox%3D%220%200%2010%2010%22%20class%3D%22marker%20flowchart%22%20id%3D%22svg_flowchart-circleStart%22%3E%3Ccircle%20style%3D%22stroke-width%3A%201%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20r%3D%225%22%20cy%3D%225%22%20cx%3D%225%22%3E%3C%2Fcircle%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225.2%22%20refX%3D%2212%22%20viewBox%3D%220%200%2011%2011%22%20class%3D%22marker%20cross%20flowchart%22%20id%3D%22svg_flowchart-crossEnd%22%3E%3Cpath%20style%3D%22stroke-width%3A%202%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%201%2C1%20l%209%2C9%20M%2010%2C1%20l%20-9%2C9%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cmarker%20orient%3D%22auto%22%20markerHeight%3D%2211%22%20markerWidth%3D%2211%22%20markerUnits%3D%22userSpaceOnUse%22%20refY%3D%225.2%22%20refX%3D%22-1%22%20viewBox%3D%220%200%2011%2011%22%20class%3D%22marker%20cross%20flowchart%22%20id%3D%22svg_flowchart-crossStart%22%3E%3Cpath%20style%3D%22stroke-width%3A%202%3B%20stroke-dasharray%3A%201%2C%200%3B%22%20class%3D%22arrowMarkerPath%22%20d%3D%22M%201%2C1%20l%209%2C9%20M%2010%2C1%20l%20-9%2C9%22%3E%3C%2Fpath%3E%3C%2Fmarker%3E%3Cg%20class%3D%22root%22%3E%3Cg%20class%3D%22clusters%22%3E%3C%2Fg%3E%3Cg%20class%3D%22edgePaths%22%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Start%20LE-CalcHash%22%20id%3D%22L-Start-CalcHash-0%22%20d%3D%22M236.75%2C36L236.75%2C40.167C236.75%2C44.333%2C236.75%2C52.667%2C236.75%2C60.117C236.75%2C67.567%2C236.75%2C74.133%2C236.75%2C77.417L236.75%2C80.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-CalcHash%20LE-FindPos%22%20id%3D%22L-CalcHash-FindPos-0%22%20d%3D%22M236.75%2C122L236.75%2C126.167C236.75%2C130.333%2C236.75%2C138.667%2C236.75%2C146.117C236.75%2C153.567%2C236.75%2C160.133%2C236.75%2C163.417L236.75%2C166.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-FindPos%20LE-CheckPos%22%20id%3D%22L-FindPos-CheckPos-0%22%20d%3D%22M236.75%2C208L236.75%2C212.167C236.75%2C216.333%2C236.75%2C224.667%2C236.816%2C232.2C236.882%2C239.734%2C237.014%2C246.467%2C237.08%2C249.834L237.146%2C253.201%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-CheckPos%20LE-AddObj%22%20id%3D%22L-CheckPos-AddObj-0%22%20d%3D%22M181.025%2C390.275L158.188%2C405.479C135.35%2C420.683%2C89.675%2C451.092%2C66.838%2C486.963C44%2C522.833%2C44%2C564.167%2C44%2C605.5C44%2C646.833%2C44%2C688.167%2C44%2C713.867C44%2C739.567%2C44%2C749.633%2C44%2C754.667L44%2C759.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-CheckPos%20LE-UseEquals%22%20id%3D%22L-CheckPos-UseEquals-0%22%20d%3D%22M274.167%2C409.583L281.889%2C421.569C289.611%2C433.555%2C305.056%2C457.528%2C312.849%2C474.631C320.642%2C491.734%2C320.784%2C501.967%2C320.855%2C507.084L320.926%2C512.201%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-UseEquals%20LE-Reject%22%20id%3D%22L-UseEquals-Reject-0%22%20d%3D%22M279.599%2C653.099L268.249%2C665.832C256.899%2C678.566%2C234.2%2C704.033%2C222.85%2C721.8C211.5%2C739.567%2C211.5%2C749.633%2C211.5%2C754.667L211.5%2C759.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-UseEquals%20LE-AddChain%22%20id%3D%22L-UseEquals-AddChain-0%22%20d%3D%22M362.401%2C653.099L373.584%2C665.832C384.768%2C678.566%2C407.134%2C704.033%2C418.317%2C721.8C429.5%2C739.567%2C429.5%2C749.633%2C429.5%2C754.667L429.5%2C759.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-AddObj%20LE-End%22%20id%3D%22L-AddObj-End-0%22%20d%3D%22M44%2C801L44%2C805.167C44%2C809.333%2C44%2C817.667%2C66.394%2C827.582C88.789%2C837.498%2C133.578%2C848.996%2C155.972%2C854.745L178.366%2C860.494%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-Reject%20LE-End%22%20id%3D%22L-Reject-End-0%22%20d%3D%22M211.5%2C801L211.5%2C805.167C211.5%2C809.333%2C211.5%2C817.667%2C211.5%2C825.117C211.5%2C832.567%2C211.5%2C839.133%2C211.5%2C842.417L211.5%2C845.7%22%3E%3C%2Fpath%3E%3Cpath%20marker-end%3D%22url(%23svg_flowchart-pointEnd)%22%20style%3D%22fill%3Anone%3B%22%20class%3D%22edge-thickness-normal%20edge-pattern-solid%20flowchart-link%20LS-AddChain%20LE-End%22%20id%3D%22L-AddChain-End-0%22%20d%3D%22M429.5%2C801L429.5%2C805.167C429.5%2C809.333%2C429.5%2C817.667%2C398.7%2C827.909C367.9%2C838.15%2C306.3%2C850.301%2C275.5%2C856.376L244.7%2C862.451%22%3E%3C%2Fpath%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabels%22%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(44%2C%20605.5)%22%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(-8%2C%20-10.5)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2216%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%E5%90%A6%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(320.5%2C%20481.5)%22%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(-8%2C%20-10.5)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2216%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%E6%98%AF%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(211.5%2C%20729.5)%22%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(-35%2C%20-10.5)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2270%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3Etrue%20%E7%9B%B8%E5%90%8C%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(429.5%2C%20729.5)%22%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(-37.5%2C%20-10.5)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2275%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3Efalse%20%E4%B8%8D%E5%90%8C%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22edgeLabel%22%3E%3Cg%20transform%3D%22translate(0%2C%200)%22%20class%3D%22label%22%3E%3CforeignObject%20height%3D%220%22%20width%3D%220%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22edgeLabel%22%3E%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20class%3D%22nodes%22%3E%3Cg%20transform%3D%22translate(236.75%2C%2018)%22%20data-id%3D%22Start%22%20data-node%3D%22true%22%20id%3D%22flowchart-Start-0%22%20class%3D%22node%20default%20processStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%2288%22%20y%3D%22-18%22%20x%3D%22-44%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-32%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2264%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E6%B7%BB%E5%8A%A0%E5%AF%B9%E8%B1%A1%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(236.75%2C%20104)%22%20data-id%3D%22CalcHash%22%20data-node%3D%22true%22%20id%3D%22flowchart-CalcHash-1%22%20class%3D%22node%20default%20processStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22140%22%20y%3D%22-18%22%20x%3D%22-70%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-58%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22116%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E8%AE%A1%E7%AE%97%20hashCode%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(236.75%2C%20190)%22%20data-id%3D%22FindPos%22%20data-node%3D%22true%22%20id%3D%22flowchart-FindPos-3%22%20class%3D%22node%20default%20processStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22168%22%20y%3D%22-18%22%20x%3D%22-84%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-72%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22144%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E6%A0%B9%E6%8D%AE%E5%93%88%E5%B8%8C%E7%A0%81%E7%A1%AE%E5%AE%9A%E4%BD%8D%E7%BD%AE%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(236.75%2C%20352)%22%20data-id%3D%22CheckPos%22%20data-node%3D%22true%22%20id%3D%22flowchart-CheckPos-5%22%20class%3D%22node%20default%20decisionStyle%20flowchart-label%22%3E%3Cpolygon%20style%3D%22%22%20transform%3D%22translate(-94%2C94)%22%20class%3D%22label-container%22%20points%3D%2294%2C0%20188%2C-94%2094%2C-188%200%2C-94%22%3E%3C%2Fpolygon%3E%3Cg%20transform%3D%22translate(-68.5%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22137%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E8%AF%A5%E4%BD%8D%E7%BD%AE%E6%98%AF%E5%90%A6%E6%9C%89%E5%AF%B9%E8%B1%A1%3F%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(44%2C%20783)%22%20data-id%3D%22AddObj%22%20data-node%3D%22true%22%20id%3D%22flowchart-AddObj-7%22%20class%3D%22node%20default%20successStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%2288%22%20y%3D%22-18%22%20x%3D%22-44%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-32%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2264%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E7%9B%B4%E6%8E%A5%E6%B7%BB%E5%8A%A0%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(320.5%2C%20605.5)%22%20data-id%3D%22UseEquals%22%20data-node%3D%22true%22%20id%3D%22flowchart-UseEquals-9%22%20class%3D%22node%20default%20decisionStyle%20flowchart-label%22%3E%3Cpolygon%20style%3D%22%22%20transform%3D%22translate(-88.5%2C88.5)%22%20class%3D%22label-container%22%20points%3D%2288.5%2C0%20177%2C-88.5%2088.5%2C-177%200%2C-88.5%22%3E%3C%2Fpolygon%3E%3Cg%20transform%3D%22translate(-63%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22126%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E8%B0%83%E7%94%A8%20equals%20%E6%AF%94%E8%BE%83%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(211.5%2C%20783)%22%20data-id%3D%22Reject%22%20data-node%3D%22true%22%20id%3D%22flowchart-Reject-11%22%20class%3D%22node%20default%20failStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22147%22%20y%3D%22-18%22%20x%3D%22-73.5%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-61.5%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22123%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E4%B8%8D%E6%B7%BB%E5%8A%A0%2C%E8%BF%94%E5%9B%9Efalse%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(429.5%2C%20783)%22%20data-id%3D%22AddChain%22%20data-node%3D%22true%22%20id%3D%22flowchart-AddChain-13%22%20class%3D%22node%20default%20successStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%22189%22%20y%3D%22-18%22%20x%3D%22-94.5%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-82.5%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%22165%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E4%BB%A5%E9%93%BE%E8%A1%A8%2F%E7%BA%A2%E9%BB%91%E6%A0%91%E5%BD%A2%E5%BC%8F%E6%B7%BB%E5%8A%A0%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3Cg%20transform%3D%22translate(211.5%2C%20869)%22%20data-id%3D%22End%22%20data-node%3D%22true%22%20id%3D%22flowchart-End-15%22%20class%3D%22node%20default%20processStyle%20flowchart-label%22%3E%3Crect%20height%3D%2236%22%20width%3D%2256%22%20y%3D%22-18%22%20x%3D%22-28%22%20ry%3D%2218%22%20rx%3D%2218%22%20style%3D%22%22%3E%3C%2Frect%3E%3Cg%20transform%3D%22translate(-16%2C%20-10.5)%22%20style%3D%22%22%20class%3D%22label%22%3E%3Crect%3E%3C%2Frect%3E%3CforeignObject%20height%3D%2221%22%20width%3D%2232%22%3E%3Cdiv%20style%3D%22display%3A%20inline-block%3B%20white-space%3A%20nowrap%3B%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxhtml%22%3E%3Cspan%20class%3D%22nodeLabel%22%3E%E7%BB%93%E6%9D%9F%3C%2Fspan%3E%3C%2Fdiv%3E%3C%2FforeignObject%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E)
public class Student {
private String name;
private int age;
@Override
public int hashCode() {
return Objects.hash(name, age);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Student student = (Student) o;
return age == student.age && Objects.equals(name, student.name);
}
}
HashSet 添加元素流程:
- 计算对象的
hashCode() - 根据哈希码确定存储位置
- 如果该位置已有对象,用
equals()判断是否相同 - 相同则不添加,不同则以链表/红黑树形式存储
为什么需要 hashCode()?
提高效率!如果只用 equals(),添加 n 个元素需要比较 O(n²) 次;有了 hashCode(),只需比较少量冲突的对象。
为什么重写 equals() 必须重写 hashCode()?
Java 规范要求:
- 如果
equals()返回 true,两个对象的hashCode()必须相同 - 如果
hashCode()相同,equals()可以返回 false(哈希冲突)
违反规范的后果:
class Student {
String name;
public Student(String name) { this.name = name; }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Student student = (Student) o;
return Objects.equals(name, student.name);
}
// 忘记重写 hashCode()
}
// 问题演示
Set<Student> set = new HashSet<>();
Student s1 = new Student("张三");
Student s2 = new Student("张三");
set.add(s1);
set.add(s2);
System.out.println(set.size()); // 2 (应该是 1)
System.out.println(s1.equals(s2)); // true
System.out.println(set.contains(s2)); // 可能是 false
正确实现:
@Override
public int hashCode() {
return Objects.hash(name); // 使用工具类
}
💬 评论