我们常说,Java是一种面向对象的语言,因而在Java中几乎所有的操作都离不开对象.而在Java语言中,最常见的创建对象的方法是通过对类构造器的调用,除此之外,其实还有下面几种可以创建对象的方法. 1)通过反射机制来创建对象; class Person{ String name="Jack"; public Person(){ System.out.println("construct"); } public String toString(){return nam
一般this在各类语言中都表示“调用当前函数的对象”,java中也存在这种用法: public class Leaf { int i = 0; Leaf increment(){ i++; return this; //this指代调用increment()函数的对象 } void print(){ System.out.println("i = " + i); } public static void main(String[] args) { Leaf x = new Leaf()