java dispose非静态_java中的清理问题 s.dispose(); 这有什么用???

classComponent1{Component1(){println("Component1()");}voiddispose(){println("Component1.dispose()");}}classComponent2{Component2(){println("Component2()");}voiddispose(){...

class Component1 {

Component1() { println("Component1()"); }

void dispose() { println("Component1.dispose()"); }

}

class Component2 {

Component2() { println("Component2()"); }

void dispose() { println("Component2.dispose()"); }

}

class Component3 {

Component3() { println("Component3()"); }

void dispose() { println("Component3.dispose()"); }

}

class Root2 {

Component1 c1root;

Component2 c2root;

Component3 c3root;

Root2() {

println("Root()");

c1root = new Component1();

c2root = new Component2();

c3root = new Component3();

}

void dispose() {

c3root.dispose();

c2root.dispose();

c1root.dispose();

println("Root2.dispose()");

}

}

class Stem2 extends Root2 {

Component1 c1stem;

Component2 c2stem;

Component3 c3stem;

Stem2() {

super();

println("Stem2()");

c1stem = new Component1();

c2stem = new Component2();

c3stem = new Component3();

}

void dispose() {

c3stem.dispose();

c2stem.dispose();

c1stem.dispose();

super.dispose();

println("Stem2.dispose()");

}

public static void main(String[] args) {

Stem2 s = new Stem2();

try {

// Code and exception handling...

} finally {

s.dispose();这有什么用???

}

}

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值