码迷,mamicode.com
首页 > 其他好文 > 详细

图说jdk1.8新特性(5)--- 编译器新特性

时间:2019-10-30 13:19:02      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:rem   图片   image   lin   syn   没有   src   his   新特性   

技术图片

技术图片

/**
     * Returns the name of the parameter.  If the parameter's name is
     * {@linkplain #isNamePresent() present}, then this method returns
     * the name provided by the class file. Otherwise, this method
     * synthesizes a name of the form argN, where N is the index of
     * the parameter in the descriptor of the method which declares
     * the parameter.
     *
     * @return The name of the parameter, either provided by the class
     *         file or synthesized if the class file does not provide
     *         a name.
     */
    public String getName() {
        // Note: empty strings as paramete names are now outlawed.
        // The .equals("") is for compatibility with current JVM
        // behavior.  It may be removed at some point.
        if(name == null || name.equals(""))
            return "arg" + index;
        else
            return name;
    }

说明:

  • jdk1.8反射包增加了Parameter类,通过该类的getName方法能在运行时得到参数的名称
  • 如果没有通过-parameters指定编译器在编译的时候将参数名编译进去,那么得到的参数名称将会是arg1、arg2、arg3这种默认的参数名

图说jdk1.8新特性(5)--- 编译器新特性

标签:rem   图片   image   lin   syn   没有   src   his   新特性   

原文地址:https://www.cnblogs.com/Kidezyq/p/11763988.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!