package com.example.domain;

public class Product {
    private Long id;
    private  String name;

    public Product(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    public static void main(String[] args){
        Product product = new Product(1L,"demo");
        System.out.println(product.toString());
        change(product);
        System.out.println(product.toString());
    }
    public static void change(Product product){
        product.setName("demo_1");
        product.setId(2L);
        System.out.println(product.toString());
        product = new Product(3L, "demo_2");
        System.out.println(product.toString());
    }
}

 以上代码的输出结果:

Product{id=1, name='demo'}
Product{id=2, name='demo_1'}
Product{id=3, name='demo_2'}
Product{id=2, name='demo_1'}

  

 

相关文章:

  • 2021-09-26
  • 2021-10-10
  • 2021-07-04
  • 2021-10-22
  • 2021-07-22
  • 2021-08-01
  • 2021-10-31
  • 2022-12-23
猜你喜欢
  • 2021-11-24
  • 2022-02-09
  • 2022-12-23
  • 2021-06-24
  • 2021-07-17
  • 2022-01-04
  • 2021-11-08
相关资源
相似解决方案