public class RoroTest {
String name ="";
String age ="";
Car car ;
public static void main(String[] args) {
Car car1;
car1 = new Car();
car1.setType("小汽车");
RoroTest roro ;
roro = new RoroTest();
roro.setCar(car1);
//以上方法只是为了准备数据
Car car2 ;
car2 = new Car();
car2.setType("卡车");
roro.setCar(car2);
System.err.println(roro.getCar().type);
List<RoroTest> list = new LinkedList<>();
for(RoroTest roroTest : list) {
Car car2 ;
car2 = new Car();
car2.setType("卡车");
roroTest.setCar(car2);
System.err.println(roro.getCar().type);
}
Car car3 ;
car3 = roro.getCar();
car3.setType("卡车");
roro.setCar(car3);
System.err.println(roro.getCar().type);
String name ="";
String age ="";
Car car ;
public static void main(String[] args) {
Car car1;
car1 = new Car();
car1.setType("小汽车");
RoroTest roro ;
roro = new RoroTest();
roro.setCar(car1);
//以上方法只是为了准备数据
Car car2 ;
car2 = new Car();
car2.setType("卡车");
roro.setCar(car2);
System.err.println(roro.getCar().type);
List<RoroTest> list = new LinkedList<>();
for(RoroTest roroTest : list) {
Car car2 ;
car2 = new Car();
car2.setType("卡车");
roroTest.setCar(car2);
System.err.println(roro.getCar().type);
}
Car car3 ;
car3 = roro.getCar();
car3.setType("卡车");
roro.setCar(car3);
System.err.println(roro.getCar().type);
}
set是把当前属性覆盖掉的意思,new相当于在内存里边新建的一个对象,而get是拿到内存里边已经有的那个对象,所以相对来说不是很很损害内存的。