Доброго времени суток!
Недавно начал изучать Java и споткнулся на конструкторах.
package com.company.personidentity;
public class Main {
public static void main(String[] args) {
Person person1 = new Person("Harry Potter", 40, "Baker street 20","Manchester","United Kingdom");
}
}
Intellij IDEA уже подсказывает, что имеется несоответствие типов, у меня имеется тип Address, а я вроде как подсовываю String. Как эту проблему решить? Хочу, чтобы адрес был отдельным классом
package com.company.personidentity;
public class Person {
private String name;
private int age;
private Address address;
private Address city;
private Address country;
public Person(String name, int age, Address address, Address city, Address country) {
this.name = name;
this.age = age;
this.address = address;
this.city = city;
this.country = country;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
", address=" + address +
", city=" + city +
", country=" + country +
'}';
}
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 Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Address getCity() {
return city;
}
public void setCity(Address city) {
this.city = city;
}
public Address getCountry() {
return country;
}
public void setCountry(Address country) {
this.country = country;
}
}
package com.company.personidentity;
public class Person {
private String name;
private int age;
private Address address;
private Address city;
private Address country;
public Person(String name, int age, Address address, Address city, Address country) {
this.name = name;
this.age = age;
this.address = address;
this.city = city;
this.country = country;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + '\'' +
", age=" + age +
", address=" + address +
", city=" + city +
", country=" + country +
'}';
}
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 Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Address getCity() {
return city;
}
public void setCity(Address city) {
this.city = city;
}
public Address getCountry() {
return country;
}
public void setCountry(Address country) {
this.country = country;
}
}