前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >图说jdk1.8新特性(5)--- 编译器新特性

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

作者头像
SecondWorld
发布2019-10-31 20:27:44
3300
发布2019-10-31 20:27:44
举报
文章被收录于专栏:Java开发者杂谈Java开发者杂谈
代码语言:javascript
复制
/**
     * 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这种默认的参数名
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-10-30 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档