A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 郭彦君 中级黑马   /  2013-4-7 17:54  /  1612 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 郭彦君 于 2013-4-7 19:55 编辑
  1. class ReflectionClass{
  2.         public static void main(String [] args){
  3.               String [] arr4 = new String[3];

  4.               System.out.println(arr4.getClass().getName());//[Ljava.lang.String
  5.         }
  6. }
复制代码
打印结果是[Ljava.lang.String
我知道[代表数组的意思,那L代表什么?查文档只有基本数据类型的简写

评分

参与人数 1技术分 +1 收起 理由
陈丽莉 + 1

查看全部评分

6 个回复

倒序浏览
[ 表示一维数组,L代表是引用数据类型的数组~

基本数据类型的每种类型都有自已对应的标识符,就是上面那个图~

"java.lang.String"是数组元素的类型,标识这个数组是String类型的数组。

评分

参与人数 1技术分 +1 收起 理由
陈丽莉 + 1

查看全部评分

回复 使用道具 举报
[  表示一维数组,[[ 二维数组…… L  表示是对象类型 .[Ljava.lang.String 可以理解了吧.而java.lang.String  这个就是字符串了

评分

参与人数 1技术分 +1 收起 理由
陈丽莉 + 1

查看全部评分

回复 使用道具 举报
关于:XX.getClass().getName();
给你getName()方法的源码,看看自己能明白点什么不(你想要的答案 方法注释的举例中就有,别忘了亲,java是开源的,其他的THML样式和看不懂的要学会忽略)
  1. /**
  2.      * Returns the  name of the entity (class, interface, array class,
  3.      * primitive type, or void) represented by this <tt>Class</tt> object,
  4.      * as a <tt>String</tt>.
  5.      *
  6.      * <p> If this class object represents a reference type that is not an
  7.      * array type then the binary name of the class is returned, as specified
  8.      * by the Java Language Specification, Second Edition.
  9.      *
  10.      * <p> If this class object represents a primitive type or void, then the
  11.      * name returned is a <tt>String</tt> equal to the Java language
  12.      * keyword corresponding to the primitive type or void.
  13.      *
  14.      * <p> If this class object represents a class of arrays, then the internal
  15.      * form of the name consists of the name of the element type preceded by
  16.      * one or more '<tt>[</tt>' characters representing the depth of the array
  17.      * nesting.  The encoding of element type names is as follows:
  18.      *
  19.      * <blockquote><table summary="Element types and encodings">
  20.      * <tr><th> Element Type <th> &nbsp;&nbsp;&nbsp; <th> Encoding
  21.      * <tr><td> boolean      <td> &nbsp;&nbsp;&nbsp; <td align=center> Z
  22.      * <tr><td> byte         <td> &nbsp;&nbsp;&nbsp; <td align=center> B
  23.      * <tr><td> char         <td> &nbsp;&nbsp;&nbsp; <td align=center> C
  24.      * <tr><td> class or interface  
  25.      *                       <td> &nbsp;&nbsp;&nbsp; <td align=center> L<i>classname</i>;
  26.      * <tr><td> double       <td> &nbsp;&nbsp;&nbsp; <td align=center> D
  27.      * <tr><td> float        <td> &nbsp;&nbsp;&nbsp; <td align=center> F
  28.      * <tr><td> int          <td> &nbsp;&nbsp;&nbsp; <td align=center> I
  29.      * <tr><td> long         <td> &nbsp;&nbsp;&nbsp; <td align=center> J
  30.      * <tr><td> short        <td> &nbsp;&nbsp;&nbsp; <td align=center> S
  31.      * </table></blockquote>
  32.      *
  33.      * <p> The class or interface name <i>classname</i> is the binary name of
  34.      * the class specified above.
  35.      *
  36.      * <p> Examples:
  37.      * <blockquote><pre>
  38.      * String.class.getName()
  39.      *     returns "java.lang.String"
  40.      * byte.class.getName()
  41.      *     returns "byte"
  42.      * (new Object[3]).getClass().getName()
  43.      *     returns "[Ljava.lang.Object;"
  44.      * (new int[3][4][5][6][7][8][9]).getClass().getName()
  45.      *     returns "[[[[[[[I"
  46.      * </pre></blockquote>
  47.      *
  48.      * @return  the name of the class or interface
  49.      *          represented by this object.
  50.      */
  51.     public String getName() {
  52.         if (name == null)
  53.             name = getName0();
  54.         return name;
  55.     }
复制代码

评分

参与人数 1技术分 +1 收起 理由
陈丽莉 + 1

查看全部评分

回复 使用道具 举报
对了,这个方法是Class.claass这个特殊类中的方法,你前面的.getClaass()的返回值就是Class类型的,所以你才能在后面.getName()
回复 使用道具 举报
[  表示一维数组,[[ 二维数组…… L  表示是对象类型 .
你可以可以写个测试类试试
System.out.println("数组"+String[].class);
回复 使用道具 举报
谢谢各位大神,搞懂了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马