自定义的注解
@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
通过反射和自定义注解,实现对map的匹配(泛型)
最新推荐文章于 2022-09-25 12:13:13 发布
本文介绍了如何结合反射机制和自定义注解,有效地实现对Map对象中泛型类型的匹配与操作,提升代码的灵活性和可维护性。
摘要由CSDN通过智能技术生成