本文共 1299 字,大约阅读时间需要 4 分钟。
感觉定义要比PYTHON严谨很多,一切源于静态语言的特点吧。。
于是语法上就复杂很多,值不值得呢?
参考测试URL:
http://www.cnblogs.com/lwbqqyumidi/p/3837629.html
import java.util.*;public class TestCollection { public static void main(String args[]) { Listlist = new ArrayList (); list.add("QQYmydmidi"); list.add("corn"); //list.add(100); for (int i=0; i < list.size(); i++) { String name = (String) list.get(i); System.out.println("name: " + name); } Box name = new Box ("coooorn"); Box age = new Box (712); Box number = new Box (314); System.out.println("name: " + name.getData()); System.out.println("age: " + age.getData()); System.out.println("name class: " + name.getClass()); System.out.println("age class: " + age.getClass()); System.out.println(name.getClass() == age.getClass()); getData(name); getData(age); getData(number); //getUpperNumberData(name); getUpperNumberData(age); getUpperNumberData(number); } public static void getData(Box data) { System.out.println("data: " + data.getData()); } public static void getUpperNumberData(Box data) { System.out.println("data: " + data.getData()); }}class Box { private T data; public Box(){}; public Box(T data) { this.data = data; } public T getData() { return data; }}