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'}
作者:BosyJ
轉載:https://www.cnblogs.com/pejsidney/
本站使用「署名 4.0 国际」创作共享协议,转载请在文章明显位置注明作者及出处。