`
jaesonchen
  • 浏览: 311647 次
  • 来自: ...
社区版块
存档分类
最新评论
文章列表
public class FinallyTest { public static void main(String[] args) { System.out.println("test1:" + testFinal1()); System.out.println("test2:" + testFinal2()); System.out.println("test3:" + testFinal3()); System.out.println("test4:" + testFinal4() ...
import java.util.*; public class Generics { //无限制的通配符类型 static int numElementsInCommon(Set<?> s1, Set<?> s2) { int result = 0; for (Object o : s1) if (s2.contains(o)) result++; return result; } private Map<Class<?>, Object> favorites = new Ha ...

java 内部类

public class InnerTest { public static void main(String[] args) { //必须先有外部类的对象才能生成内部类的对象,因为内部类的作用就是为了访问外部类中的成员变量 Outer.Inner in = new Outer().new Inner(); //out.new Inner() in.show(); in.show1(); new Outer().show2(); new Outer().show3(166); Test test = new Oute ...
import java.lang.reflect.*; public class Reflection { public static void main(String[] args) { ReflectPerson p = new ReflectPerson("chenzq", 20); Class<? extends ReflectPerson> c1 = p.getClass(); System.out.println(c1); Class<String> c2 = String.class; ...
import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.lang.reflect.UndeclaredThrowableException; public class BusinessProxyGenerateByJdk extends Proxy implements Business { private static final long serialVersionUI ...
public class ProducerAndConsumer { public static void main(String[] args) { Storage storage = new Storage(); Thread producer1 = new Thread(new Producer(storage, "producer1")); Thread producer2 = new Thread(new Producer(storage, "producer2")); Thread produ ...
public class InitialOderExtends extends Parent { // 静态变量 public static String s_StaticField = "subclass--static variable"; // 变量 public String s_Field = "subclass--variable"; // 静态初始化块 static { System.out.println(s_StaticField); System.out.println(&qu ...
public class EnumObject { public static void main(String[] args) { double x = 1.11; double y = 2.01; for (Operation op : Operation.values()) System.out.printf("%f %s %f = %f%n", x, op, y, op.apply(x, y)); System.out.println(Operation.valueOf("MINUS"). ...
public class AutoBoxing { public static void sum() { long start = new java.util.Date().getTime(); //使用基本数据类型 long sum = 0L; for(long i = 0; i < Integer.MAX_VALUE; i++) { sum += i; } long end = new java.util.Date().getTime(); System.out.println("total = &quo ...
import java.lang.annotation.*; import java.lang.reflect.*; public class Annotation { public static void main(String[] args) { int tests = 0; int passed = 0; Class<?> testClass = AnnotationTest.class; for (Method m : testClass.getDeclaredMethods()) { if (m.isAnnotationP ...
public class LabeledLoop { public static void main(String[] args) { int i = 0; outer: // Can't have statements here for(; true ;) { inner: // Can't have statements here for(; i < 10; i++) { prt("i = " + i); if(i == 2) { prt("continue"); ...
import java.lang.reflect.Method; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; //直接使用代理类的父类作为目标业务对象。 public class BusinessCglibProxy1 implements MethodInterceptor { private st ...
import java.lang.reflect.Method; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; import net.sf.cglib.proxy.Callback; import net.sf.cglib.proxy.CallbackFilter; public class BusinessCglibProxyFilter { private static C ...
public interface Business { public void service(); public void execute(); } public class BusinessImpl implements Business { private String id = "default"; public BusinessImpl() {} public BusinessImpl(String id) { this.id = id; } @Override public void service( ...
import java.lang.reflect.Method; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; //传入业务类实例作为目标对象。 public class BusinessCglibProxy2 implements MethodInterceptor { //拦截器持有真正的业务对象 private Object target; private Bus ...
Global site tag (gtag.js) - Google Analytics