Appendix

Immutability:

String are immutable.

Wrappers are immutable.

Integer iWrap = new Integer(42);
There is no setter method for a wrapper object.

You can't change the value of String/Wrapper unless you refer it to another object.


Assertions:

To run with assertions:

java -ea applicaiton

Static nested classes are just like a static member.


Access level:

class is either public or default.

default: keep everything in the package.

protected: default and allows subclasses to inherit the protected thing outside the package.


Enumerations

public enum Members {JERRY, BOBBY, PHIL};
public Members member;
// == and equals() are the same.

Constant-specific class body:

public class EnumTest {
	enum Names {
		JERRY("lead guitar") {
			@Override
			public String sings() {
				return "heihei";
			}
		},
		BOBO("bass");
		
		private String instrument;
		
		Names(String instrument) {
			this.instrument = instrument;
		}
		
		public String getInstrument() {
			return instrument;
		}
		
		public String sings() {
			return "hahaha";
		}
	}
	
	public static void main(String[] args) {
		for (Names n : Names.values()) {
			System.out.println(n + " " + n.getInstrument() + " " + n.sings());
		}
	}
}
Elements are static and must be declared at the beginning.

Enumeration can have constructors and methods since it is a class.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值