1. import java.util.*;
2.
3. public class EmployeeTest
4. {
5. public static void main(String[] args)
6. {
7. // fill the staff array with three Employee objects
8. Employee[] staff = new Employee[3];
9.
10. staff[0] = new Employee("Carl Cracker", 75000, 1987, 12, 15);
11. staff[1] = new Employee("Harry Hacker", 50000, 1989, 10, 1);
12. staff[2] = new Employee("Tony Tester", 40000, 1990, 3, 15);
13.
14. // raise everyone's salary by 5%
15. for (Employee e : staff)
16. e.raiseSalary(5);
17.
18. // print out information about all Employee objects
19. for (Employee e : staff)
20. System.out.println("name=" + e.getName()
21. + ",salary=" + e.getSalary()
22. + ",hireDay=" + e.getHireDay());
23. }
24. }
25.
26. class Employee
27. {
28. public Employee(String n, double s, int year, int month, int day)
29. {
30. name = n;
31. salary = s;
32. GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
33. // GregorianCalendar uses 0 for January
34. hireDay = calendar.getTime();
35. }
36.
37. public String getName()
38. {
39. return name;
40. }
41.
42. public double getSalary()
43. {
44. return salary;
45. }
46.
47. public Date getHireDay()
48. {
49. return hireDay;
50. }
51.
52. public void raiseSalary(double byPercent)
53. {
54. double raise = salary * byPercent / 100;
55. salary += raise;
56. }
57.
58. private String name;
59. private double salary;
60. private Date hireDay;
61. }
上面这段程序,在1.5里面就会run 成功,但是,1。6。2 就不行。
问题如下:
incompatible types
麻烦诸位了,上面这段程序从java 2 核心技术 copy 过来的。
2.
3. public class EmployeeTest
4. {
5. public static void main(String[] args)
6. {
7. // fill the staff array with three Employee objects
8. Employee[] staff = new Employee[3];
9.
10. staff[0] = new Employee("Carl Cracker", 75000, 1987, 12, 15);
11. staff[1] = new Employee("Harry Hacker", 50000, 1989, 10, 1);
12. staff[2] = new Employee("Tony Tester", 40000, 1990, 3, 15);
13.
14. // raise everyone's salary by 5%
15. for (Employee e : staff)
16. e.raiseSalary(5);
17.
18. // print out information about all Employee objects
19. for (Employee e : staff)
20. System.out.println("name=" + e.getName()
21. + ",salary=" + e.getSalary()
22. + ",hireDay=" + e.getHireDay());
23. }
24. }
25.
26. class Employee
27. {
28. public Employee(String n, double s, int year, int month, int day)
29. {
30. name = n;
31. salary = s;
32. GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
33. // GregorianCalendar uses 0 for January
34. hireDay = calendar.getTime();
35. }
36.
37. public String getName()
38. {
39. return name;
40. }
41.
42. public double getSalary()
43. {
44. return salary;
45. }
46.
47. public Date getHireDay()
48. {
49. return hireDay;
50. }
51.
52. public void raiseSalary(double byPercent)
53. {
54. double raise = salary * byPercent / 100;
55. salary += raise;
56. }
57.
58. private String name;
59. private double salary;
60. private Date hireDay;
61. }
上面这段程序,在1.5里面就会run 成功,但是,1。6。2 就不行。
问题如下:
incompatible types
麻烦诸位了,上面这段程序从java 2 核心技术 copy 过来的。
name= Carl Cracker ,salary= 78750.0,hireDay= Tue Dec 15 00:00:00 CST 1987
name= Harry Hacker ,salary= 52500.0,hireDay= Sun Oct 01 00:00:00 CST 1989
name= Tony Tester ,salary= 42000.0,hireDay= Thu Mar 15 00:00:00 CST 1990
没有报错,希望对你有些帮助。
就过去了。大家一起来研究研究。为啥呢