JAVA常用代码

一. 判断是否包含某个注解。
    1). 声明接口

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
public @interface HandlesAsynchronously {

}

 2). 判断是否包含当前注解。

// 判断是否需要异步执行。
            Boolean isAsync = false;
            Annotation[] annotations = handler.getClass().getAnnotations();
            for (Annotation x : annotations) {
                if (x.annotationType() == HandlesAsynchronously.class) {
                    isAsync = true;
                    break;
                }
            }

 3). java Stream toarray

Integer 数组: toArray(Integer[] :: new)
person 数组: toArray(person[] ::  new).

 4). fashjson反序列化泛型对象。

 BasePlatResponse<StorageBatchDeliveryResponseBizData> successResponse = JSON
                .parseObject(successJson, new TypeReference<BasePlatResponse<StorageBatchDeliveryResponseBizData>>() {
                });

 5). java中的前加加++和后加加++
     前++是先自加再使用 (++i)
    后++是先使用再自加 (i++)

原文地址:https://www.cnblogs.com/mrhgw/p/8067085.html