import static java.lang.Math.*; //静态导入 public class StaticImport { public static void main(String[] args) { System.out.println(Math.max(3, 6)); System.out.println(Math.abs(3 - 6)); }} System.out.println(add(2,3,5)); //重载 } public static int add(int x,int...args) //可变参数 { int sum = x; for(int i=0;i
枚举
package cn.think.day1;public class EnumDemo { //外部类修饰符只有默认和public public static void main(String[] args) { WeekDay w = WeekDay.SAT; System.out.println(WeekDay.valueOf("SUN").toString()); System.out.println(WeekDay.values().length); //枚举内的元素 } public enum WeekDay{ //内部类可以有四个修饰符 SUN(1),MON,TUE,WED,THL,FRI,SAT; private WeekDay(){//必须是私有 System.out.println("first"); } private WeekDay(int day){ System.out.println("second"); } } public enum TraffcLamp{ RED(20){ public TraffcLamp nextLamp(){ return GREEN; } }, GREEN(33){ public TraffcLamp nextLamp(){ return YELLOW; } },YELLOW(43){ public TraffcLamp nextLamp(){ return RED; } }; public abstract TraffcLamp nextLamp(); private int time; private TraffcLamp(int time){ this.time = time; } } }
反射
Java类----Class 对象 类 Class cls1 = Date.class; //获取字节码 new Date().getClass(); String str1 = "abc"; Class cls = str1.getClass(); Class cls2 = String.class; Class cls3 = Class.forName("java.lang.String"); cls1 == cls2; // true cls1 == cls3; // true //基本的 Java 类型(boolean、byte、char、short、int、long、float 和 double)和关键字 void 也表示为 Class 对象。