Java Capriccio: Scenario_2 (Java随想,第二部分)

本文提供了提升编程效率和代码质量的七大建议:使用静态类型转换及工厂方法创建对象;避免重复创建对象;消除过时引用;谨慎使用异常;避免重新初始化变量;尽可能地将类和方法声明为final;充分利用局部变量的优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[b]1.Create & Destroy an object[/b]
a.public static Type valueOf(String name);
b.factory method: Type createByName(String name);
These methods can return subclass type
[可返回子类型,而 Constructor 则不行]
Do never use 'new' to create object
[b]2.Avoid of re-create object[/b]
[b]3.Eliminate of outdated references[/b]

if(size==0)
this.array[size]==null

[b]4.Carefully use exceptions[/b]
Exceptions will effect performances of your application
[b]5.Do never re-initialize variable[/b]

-------- period 09/02,2010 1:30 pm

[b]6.Make the modifier of class 'final' as far as possible[/b]
So does the method!
[b]7.Make full use of local variables {which stored stack}[/b]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值