interface Constants {
public static final int Constants_A = 1;
public static final int Constants_B = 12;
}
public class ConstantsTest {
enum Constants2{
Constants_A,Constants_B
}
public static void doit(int c){
switch (c){
case Constants.Constants_A:
System.out.println("doit() Constants_A");
break;
case Constants.Constants_B:
System.out.println("doit() COnstants_B");
break;
}
}
public static void doit2(Constants2 c){
switch (c){
case Constants_A:
System.out.println("doit() Constants_A");
break;
case Constants_B:
System.out.println("doit() COnstants_B");
break;
}
}
public static void compare(Constants2 c){
for (int i = 0; i <Constants2.values().length ; i++) {
System.out.println(c+"与"+Constants2.values()[i]+"的比较结果为:"+c.compareTo(Constants2.values()[i]));
}
}
public static void main(String[] args) {
ConstantsTest.doit(Constants.Constants_A);
ConstantsTest.doit2(Constants2.Constants_A);
ConstantsTest.doit2(Constants2.Constants_B);
ConstantsTest.doit(3);
for (int i = 0; i <Constants2.values().length ; i++) {
System.out.println("枚举类型成员变量:"+Constants2.values()[i]);
}
compare(Constants2.valueOf("Constants_B"));
}
}
public class EnumIndexTest {
enum Constants2{
Constants_A("I am enum A"),
Constants_B("I am enum B"),
Constants_C("I am enum C"),
Constants_D(3);
private String description;
private int i = 4;
private Constants2(){}
private Constants2(String description){
this.description = description;
}
private Constants2(int i){
this.i = this.i+i;
}
public String getDescription(){
return description;
}
public int getI(){
return i;
}
}
public static void main(String[] args) {
for (int i = 0; i <Constants2.values().length ; i++) {
System.out.println(Constants2.values()[i]+"调用getDescription方法为"+Constants2.values()[i].getDescription());
}
System.out.println(Constants2.valueOf("Constants_D")+"调用getI方法为:"+Constants2.valueOf("Constants_D").getI());
}
}
import java.awt.*;
public class OverClass<T> {
private T over;
public T getOver(){
return over;
}
public void setOver(T over){
this.over = over;
}
public static void main(String[] args) {
OverClass<Boolean> over1 = new OverClass<Boolean>();
OverClass<Float> over2 = new OverClass<Float>();
over1.setOver(true);
over2.setOver(12.3F);
Boolean b = over1.getOver();
Float f = over2.getOver();
System.out.println(b);
System.out.println(f);
}
}
import java.util.HashMap;
import java.util.Map;
public class MutiOverClass<K,V> {
public Map<K,V> m = new HashMap<K,V>();
public void put(K k,V v){
m.put(k,v);
}
public V get(K k){
return m.get(k);
}
public static void main(String[] args) {
MutiOverClass<Integer,String> mu = new MutiOverClass<Integer, String>();
for (int i = 0; i < 5; i++) {
mu.put(i,"I am set "+i);
}
for (int i = 0; i < mu.m.size(); i++) {
System.out.println(mu.get(i));
}
}
}
public class ArrayClass<T> {
private T[] array;
public void setArray(T[] array) {
this.array = array;
}
public T[] getArray() {
return array;
}
public static void main(String[] args) {
ArrayClass<String> a = new ArrayClass<String>();
String[] array = {"A","b","C"};
a.setArray(array);
for (int i = 0; i <a.getArray().length ; i++) {
System.out.println(a.getArray()[i]);
}
}
}
|