2020春季软件构造 0317

Types in Java
Primitives will be stored on stack and only values will be stored.
Object reference types will be stored on heap and their id will also be stored other than values.

Static Checking and Dynamic Checking
Static checking is done in the compile process and it will make sure values match the certain types.
While dynamic checking is processed in the run time. Dynamic checking tends to find a specific value valid or not in a particular situation.
Generally speaking, dynamic checking is more strict than static checking. Code without any kind of type checking will have lowest cost but have many annoying problems.
When it comes to java, it is a statically-typed language while Exception performs like dynamic checking.

Mutability and Immutability
It is a very important part in the exam and we may be asked to analyse a mutable class and transfer it to a immutable one.
在这里插入图片描述
要将可变类转换为不可变类,我们需要使该属性为final和private。 对于那些可变属性,getter方法应该提供该属性的副本,而不是引用。 这称为防御性复制。
我们应该意识到参考与价值之间的关系。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值