java中一般方法里的this是代表调用本方法的对象,但是构造方法里的this代表的是什么呢。
java中一般方法里的this是代表调用本方法的对象,但是构造方法里的this代表的是什么呢。
日期:2017-12-16 16:47:36 人气:1
this代表你正在构造的对象。
public class Test {public Test() {System.out.println(this.toString());}public static void main(String[] args) {Test obj = new Test();System.out.println(obj.toString());}}输出的两个字符串相同(后面的数字是对象地址),说明this和obj是同一个对象。
这里this就是正在构建的CommunicationD