浅谈 Java 中 this 的使用(转)[@more@]
1. this是指当前对象自己。 当在一个类中要明确指出使用对象自己的的变量或函数时就应该加上this引用。如下面这个例子中:
|
CODE:
public class A {
String s = "Hello";
public A(String s) { System.out.println("s = " + s); System.out.println("1 -> this.s = " + this.s); this.s = s; System.out.println("2 -> this.s = " + this.s); }
public static void main(String[] args) { new A("HelloWorld!"); } }
|