java教程,劲爆

Constructor.isAnnotationPresent(Class)


package test;



import java.lang.annotation.*;



public class changeData {



    public static void main(String[] args) {

        Class<persson> pClass = persson.class;

        System.out.println(pClass.isAnnotationPresent(selfAnnotation.class));

    }

}



@selfAnnotation

class persson{

    private int num;

    public int getNum(){

        return this.num;

    }

}



//第三步:添加元注解

@Target(ElementType.TYPE)

@Retention(RetentionPolicy.RUNTIME)

//第一步:定义注解

@interface selfAnnotation{

    //第二步:定义参数

    int type() default 1;

}

```



![](https://img-blog.csdnimg.cn/20210525193539784.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxODg1Njcz,size_16,color_FFFFFF,t_70)



![](https://img-blog.csdnimg.cn/20210525193624986.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxODg1Njcz,size_16,color_FFFFFF,t_70)



> 二、使用反射API读取Annotation:



```

Class.getAnnotation(Class)

Field.getAnnotation(Class)

Method.getAnnotation(Class)

Constructor.getAnnotation(Class)

package test;

import java.lang.annotation.*;

public class changeData {

public static void main(String[] args) {

    Class<persson> pClass = persson.class;

    if(pClass.isAnnotationPresent(selfAnnotation.class)){

        selfAnnotation annotation = pClass.getAnnotation(selfAnnotation.class);

        System.out.println(annotation.type());

    }

}

}

@selfAnnotation(type = 2)

class persson{

private int num;

public int getNum(){

    return this.num;

}

}

//第三步:添加元注解

@Target(ElementType.TYPE)

@Retention(RetentionPolicy.RUNTIME)

//第一步:定义注解

@interface selfAnnotation{

//第二步:定义参数

int type() default 1;

}




![](https://img-blog.csdnimg.cn/20210525194222760.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxODg1Njcz,size_16,color_FFFFFF,t_70)



> 三、读取方法参数的注解



我们都知道,一个函数的参数可以是多个,而一个参数的注解也可以是多个,所以,我们获取到的 参数的注解是一个二维数组,即第几个参数的第几个注解



package test;

import java.lang.annotation.*;

import java.lang.reflect.Method;

import java.util.Arrays;

public class changeData {

public static void main(String[] args) {

    Class<persson> pClass = persson.class;

    try {

        Method method_getNum = pClass.getMethod("getNum", int.class);

        Annotation[][] parameterAnnotations = method_getNum.getParameterAnnotations();

        System.out.println(Arrays.toString(parameterAnnotations[0]));

    } catch (NoSuchMethodException e) {

        e.printStackTrace();

    }

}

}

class persson{

private int num;

public int getNum(@two @one int a){

    return this.num;

}

}

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.PARAMETER)

@interface one{

int type() default 1;

}

@Retention(RetentionPolicy.RUNTIME)

@Target(ElementType.PARAMETER)

@interface two{

int value() default 2;

最后

都说三年是程序员的一个坎,能否晋升或者提高自己的核心竞争力,这几年就十分关键。

技术发展的这么快,从哪些方面开始学习,才能达到高级工程师水平,最后进阶到Android架构师/技术专家?我总结了这 5大块;

我搜集整理过这几年阿里,以及腾讯,字节跳动,华为,小米等公司的面试题,把面试的要求和技术点梳理成一份大而全的“ Android架构师”面试 PDF(实际上比预期多花了不少精力),包含知识脉络 + 分支细节。

Java语言与原理;
大厂,小厂。Android面试先看你熟不熟悉Java语言

高级UI与自定义view;
自定义view,Android开发的基本功。

性能调优;
数据结构算法,设计模式。都是这里面的关键基础和重点需要熟练的。

NDK开发;
未来的方向,高薪必会。

前沿技术;
组件化,热升级,热修复,框架设计

网上学习 Android的资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。希望这份系统化的技术体系对大家有一个方向参考。

我在搭建这些技术框架的时候,还整理了系统的高级进阶教程,会比自己碎片化学习效果强太多,CodeChina可见;

CodeChina开源项目地址:https://codechina.csdn.net/m0_60958482/android_p7

当然,想要深入学习并掌握这些能力,并不简单。关于如何学习,做程序员这一行什么工作强度大家都懂,但是不管工作多忙,每周也要雷打不动的抽出 2 小时用来学习。

不出半年,你就能看出变化!

我在搭建这些技术框架的时候,还整理了系统的高级进阶教程,会比自己碎片化学习效果强太多,CodeChina可见;

CodeChina开源项目地址:https://codechina.csdn.net/m0_60958482/android_p7

当然,想要深入学习并掌握这些能力,并不简单。关于如何学习,做程序员这一行什么工作强度大家都懂,但是不管工作多忙,每周也要雷打不动的抽出 2 小时用来学习。

不出半年,你就能看出变化!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值