通过反射和自定义注解,实现对map的匹配(泛型)

本文介绍了如何结合反射机制和自定义注解,有效地实现对Map对象中泛型类型的匹配与操作,提升代码的灵活性和可维护性。
摘要由CSDN通过智能技术生成
自定义的注解


@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE,ElementType.METHOD,ElementType.FIELD})
public @interface MapAnnotation {
}



@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD,ElementType.FIELD})
public @interface ListAnnotation {
}


@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE,ElementType.METHOD,ElementType.FIELD})
public @interface SetDataAnnotation {

}



@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD,ElementType.FIELD})
public @interface GetKeyAnnotation {

}



使用
        package com.android.xjq.bean.coupon;

        import com.android.banana.commlib.bean.BaseOperator;
        import com.android.banana.commlib.utils.MethodUtils;
        import com.android.banana.commlib.utils.annotation.GetKeyAnnotation;
        import com.android.banana.commlib.utils.annotation.ListAnnotation;
        import com.android.banana.commlib.utils.annotation.MapAnnotation;
        import com.android.banana.commlib.utils.annotation.SetDataAnnotation;
        import com.google.gson.annotations.Expose;

        import java.util.List;
        import java.util.Map;

        import static android.R.attr.id;
        import static android.R.attr.targetId;
        import static com.tencent.qalsdk.base.a.be;
        import static com.tencent.qalsdk.sdk.MsfCommand.getKey;

/**
 * Created by zaozao on 2018/4/26.
 */
public class LianHongCoupon extends MethodUtils implements BaseOperator {


    private boolean jumpLogin;
    private String nowDate;
    private boolean success;

    @MapAnnotation
    private Map<String, BetCouponCountBean> betCouponMap;

    @ListAnnotation
    private List<BetCouponBean> packageSubTypeList;

    private boolean hasCoupon;

    public boolean isHasCoupon() {
        return hasCoupon;
    }

    public void setHasCoupon(boolean hasCoupon) {
        this.hasCoupon = hasCoupon;
    }

    public boolean isJumpLogin() {
        return jumpLogin;
    }

    public void setJumpLogin(boolean jumpLogin) {
        this.jumpLogin = jumpLogin;
    }

    public String getNowDate() {
        return nowDate;
    }

    public void setNowDate(String nowDate) {
        this.nowDate = nowDate;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }


    public List<BetCouponBean> getPackageSubTypeList() {
        return packageSubType
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值