基础加强一(枚举)


IDE (集成开发环境) Integrition development  environment

 jndi

jms

 

Eclipse

版本设置:

编译的JDK版本

运行的JDK版本

 

自动提示设置

Proferences-->General-->Keys-Search(Context assist) 设置就成

 

Integer 与Int相互拆装箱的时候 如果在-128-127时。不会相互的值不会影响。如果超出这个值的话,拆装箱对象所指向的常量池的值不同

 

享元模式(flyweight)

如果很多很小的对象,有很多相同的东西,把他变成一个对象,把不同的对象变成属性,变成参数传进去,称之为外部状态,这就是享元模式

 

枚举

枚举内部类:

如果你想在一个类中编写各个枚举类和测试调用类,那么可以将枚举类定义成调用类的内部类

 

枚举类原理:

 

import java.io.File;

public abstract class Demo30 {

	public static final Demo30 D1 = new Demo30() {

		public Demo30 next() {
			return D2;
		};
	};

	public static final Demo30 D2 = new Demo30() {
		public Demo30 next() {

			return D3;

		};
	};

	public static final Demo30 D3 = new Demo30() {
		public Demo30 next() {
			return D4;
		};
	};

	public static final Demo30 D4 = new Demo30() {
		public Demo30 next() {
			return D5;
		};
	};

	public static final Demo30 D5 = new Demo30() {
		public Demo30 next() {
			return D1;
		};
	};

	private Demo30() {
	};

	public abstract Demo30 next();

	// public Demo30 next() {
	//
	// if (this == D1) {
	// return D2;
	// } else if (this == D2) {
	// return D3;
	// } else if (this == D3) {
	// return D4;
	// } else if (this == D4) {
	// return D5;
	// } else {
	// return D1;
	// }
	//
	// }

	public String toString() {

		return this == D1 ? "D2" : "D3";
	}

}

 

 枚举对象的使用:

注意:有枚举对象..必须最前面,最后一个加分号结束;

public enum Session {
		request, response, context, content;

	}

	public enum color {

		RED() {

			@Override
			public Demo31.color selectColor(int time) {
				System.out.println("  " + time + "秒后显示" + BLAUE);
				return BLAUE;
			}
		},
		BLAUE {
			@Override
			public color selectColor(int time) {
				System.out.println("  " + time + "秒后显示" + YELLOW);
				return YELLOW;
			}
		},
		YELLOW {
			@Override
			public color selectColor(int time) {
				System.out.println("  " + time + "秒后显示" + WHITE);
				return WHITE;
			}
		},
		WHITE {
			@Override
			public color selectColor(int time) {
				System.out.println("  " + time + "秒后显示" + RED);
				return RED;
			}
		};

		private void color() {
		};

		private void color(int time) {
		};

		public abstract color selectColor(int time);

		public color next() {
			switch (this) {
			case RED:
				return BLAUE;
			case BLAUE:
				return YELLOW;
			case YELLOW:
				return WHITE;
			case WHITE:
				return RED;
			}
			return RED;

		}

	}

	public static void main(String[] args) {
		color c = color.RED.selectColor(10);
	}


switch enum的使用

使用心德:

enum的switch一般使用在enum中的方法通过switch(this)来统一管理传回来的对象并返回相应的值

通过switch(this){

case 对象:break;

case 对象:break;

case 对象:break;

}

 


 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值