J'KYO
No pains,no gains.
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'}

  

 

posted on 2018-03-23 22:14  J'KYO  阅读(114)  评论(0编辑  收藏  举报