本帖最后由 NNERO 于 2014-4-29 22:05 编辑
- </blockquote></div><div class="blockcode"><blockquote>public class Text111
- {
- public static void main(String[] args)throws Exception
- {
- Element f = new Element("NNERO");
- Person p = new Person(9);
- f.hello(5,"St");//返回false
- f.hello("String",p);//返回false
- f.hello(5.26,9);//返回false
- f.hello(p,p);//返回true
-
- }
-
- }
- class Element{
- private String name;
- Element(String name){
- this.name = name;
- System.out.println("Hello");
- }
- public <E> void hello(E x,E y){
-
-
- System.out.println(x.equals(y));
- }
- public boolean equals(Object x){
- return true;
- }
- }
- class Person{
- private int age;
- public Person(int age) {
- super();
- this.age = age;
- }
- public String toString(){
- return age+"";
- }
- }
复制代码
我这里明明覆写了equals方法,为什么还是会返回false?
|
|