Error:(41, 50) java: 不兼容的类型: Person无法转换为java.lang.String

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Serializable;
public class Person implements Comparable, Serializable{
//从键盘上读一个人
public static Person readPerson(){
String firstName = null;
String surname = null;
try {
System.out.print("Enter first name: ");
firstName = keyboard.readLine().trim();
System.out.print("Enter surname: ");
surname = keyboard.readLine().trim();
}catch (IOException e){
System.err.println(“Error reading a name.”);
e.printStackTrace();
System.exit(1);
}
return new Person(firstName,surname);
}
private static BufferedReader keyboard = new BufferedReader(
new InputStreamReader(System.in));
public boolean equals(Object person){
return compareTo((Person)person) == 0;
}
public int hashCode(){
return 7firstName.hashCode()+13surname.hashCode();
}
//构造器
public Person(String firstName, String surname){
this.firstName = firstName;
this.surname = surname;
}
public String toString(){
return firstName + " " +surname;
}
//比较person对象
public int compareTo(Person person){
int result = surname.compareTo(person.surname);
return result == 0 ? firstName.compareTo((Person)person).firstName:result;
}
private String firstName;
private String surname;
}
Error:(41, 50) java: 不兼容的类型: Person无法转换为java.lang.String

你可能感兴趣的:(Error:(41, 50) java: 不兼容的类型: Person无法转换为java.lang.String)