属性自动注入。
Car:
public class Car { private String brand; private String color; @Override public String toString() { return "Car{" + "brand='" + brand + '\'' + ", color='" + color + '\'' + '}'; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public String getColor() { return color; } public void setColor(String color) { this.color = color; } }
MyCollection:
public class MyCollection { private String[] array; private List<String> list; private Set<String> set; private Map<String,String> map; private Properties properties; public String[] getArray() { return array; } public void setArray(String[] array) { this.array = array; } public List<String> getList() { return list; } public void setList(List<String> list) { this.list = list; } public Set<String> getSet() { return set; } public void setSet(Set<String> set) { this.set = set; } public Map<String, String> getMap() { return map; } public void setMap(Map<String, String> map) { this.map = map; } public Properties getProperties() { return properties; } public void setProperties(Properties properties) { this.properties = properties; } }
Student:
public class Student { private String name; private int age; private Car car; public Student() { } public Student(String name, int age, Car car) { this.name = name; this.age = age; this.car = car; } @Override public String toString() { return "Student{" + "name='" + name + '\'' + ", age=" + age + ", car=" + car + '}'; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public Car getCar() { return car; } public void setCar(Car car) { this.car = car; } }