日期:2014-05-20  浏览次数:20627 次

标感叹号的为报错的部分,别人写的运行都能成功可是我写的改了几次还是不能成功!郁闷,求解!
package leonardo;

import java.util.*;

public class Test {
public static void main(String[] args) {

Collection c = new ArrayList();
c.add("hello");
Name<String,String> name1 = new Name<String,String>("f1","l1");!!!!!!!!!
  c.add(name1);
  c.add(new Integer(100));
System.out.println(c.size());
System.out.println(c);
}

class Name<F,L> {
F firstName;
L lastName;

public Name( F firstName1, L lastName1) {
firstName = firstName1;
lastName = lastName1;
}

F getfirstName() {
return firstName;
}

L getlastName() {
return lastName;
}


}
}





------解决方案--------------------
Java code


import java.util.*;

public class Test {
    public static void main(String[] args) {

        Collection c = new ArrayList();
        c.add("hello");
        Name<String,String> name1 = new Name<String,String>("f1","l1");
        c.add(name1);
        c.add(new Integer(100));
        System.out.println(c.size());
        System.out.println(c);
    }

   
}

 class Name<F,L> {
        F firstName;
        L lastName;

        public Name( F firstName1, L lastName1) {
            firstName = firstName1;
            lastName = lastName1;
        }

        F getfirstName() {
            return firstName;
        }

        L getlastName() {
            return lastName;
        }


    }

------解决方案--------------------
哎,呵呵!这样的的小错误不容易发现啊!就是{}的问题!
------解决方案--------------------
探讨

Java code


import java.util.*;

public class Test {
public static void main(String[] args) {

Collection c = new ArrayList();
c.add("hello");
Name<String,String> name1 =……

------解决方案--------------------
什么运行结果有变化? 你觉得那里不对?

探讨

谢谢了 我也是刚才发完贴就发现了!我同学给我调错了还是自己不细心啊、可是我又发现了一个问题运行结果怎么会有变化呢?