public staic void main(String[] args) { String a = new String("abcd"); System.out.println(a); // the std out will print "abcd" dosomething(a); System.out.println(a); // still print "abcd" } public void dosomething(String s) { //a and s are two sucker to a coke System.out.println(s); // will print "abcd" s = s.substring(0,1); //now s is a sucker to another coke,because the method return a new coke System.out.println(s); //will print "ab" } bw: 我也是一个初学者,希望能够共同学习
no 句柄. It should be used exclusively for Windows. There's only reference in Java.
o <==> 对象引用 <==> 对象handle(句柄)
比如要生成一个新的窗口,语句为: new Frame("Frame Title");
如果我们要它构造后并显示出来,语句为:new Frame("Frame Title").show();
现在试想,以后我们还想为这个对象调用一些方法怎么办,是不是就很困难了?于是我们可以这样:
Frame frame=new Frame("Frame Title");//frame就是指向新Frame实例的句柄
frame.show();//对句柄做方法调用,效果和new Frame("Frame Title").show();是完全一样的,因为frame现在是指向它的句柄
以后,我们还可以方便地利用句柄来进行方法调用:
比如改变窗口的大小:frame.setSize(int i,int j);
也可以让它指向另一个新对象:frame=new Frame("this is a new Frame");
最后我们还可以释放它:frame=null;
public staic void main(String[] args) {
String a = new String("abcd");
System.out.println(a);
// the std out will print "abcd"
dosomething(a);
System.out.println(a);
// still print "abcd"
}
public void dosomething(String s) {
//a and s are two sucker to a coke
System.out.println(s);
// will print "abcd"
s = s.substring(0,1);
//now s is a sucker to another coke,because the method return a new coke
System.out.println(s);
//will print "ab"
}
bw: 我也是一个初学者,希望能够共同学习
概念问题。