类名.this与类名.class

news/2024/8/26 14:11:12 标签: class, exception, 虚拟机, java, c, output
cle class="tags" href="/tags/CLASS.html" title=class>class="baidu_pl">
cle_content" class="tags" href="/tags/CLASS.html" title=class>class="article_content clearfix">
content_views" class="tags" href="/tags/CLASS.html" title=class>class="htmledit_views">

原文链接:http://leiming32.blog.51cto.com/1021363/494913

1、当在内部类中使用this指的就是内部类的对象, 为了访问外层类对象,就可以使用外层类名.this来访问。
2、在class="tags" href="/tags/JAVA.html" title=java>java中࿰c;每个class="tags" href="/tags/CLASS.html" title=class>class都有一个相应的Class对象࿰c;当编写好一个类࿰c;编译完成后࿰c;在生成的.class="tags" href="/tags/CLASS.html" title=class>class文件中࿰c;就产生一        个Class对象࿰c;用来表示这个类的类型信息。获得Class实例的三种方式:
      1). 利用对象调用getClass()方法获取该对象的Class实例
      2). 使用Class的静态方法forName()࿰c;用类的名字获取一个Class实例
      3). 运用.calss的方式获取Class实例࿰c;对基本数据类型的封装类࿰c;还可以采用.TYPE来获取对应的基本数据类型的Class实例。
以下是TestClass.class="tags" href="/tags/JAVA.html" title=java>java代码:

<code class="tags" href="/tags/CLASS.html" title=class>class="language-class="tags" href="/tags/JAVA.html" title=java>java">public class="tags" href="/tags/CLASS.html" title=class>class TestClass { 
    public static void main(String[] args) { 
        // 在运行期间࿰c;如果我们要产生某个类的对象࿰c;class="tags" href="/tags/JAVA.html" title=java>javaclass="tags" href="/tags/XuNiJi.html" title=虚拟机>虚拟机会检测该类型的Class对象是否已被加载。
    	// 如果没有加载࿰c;class="tags" href="/tags/JAVA.html" title=java>javaclass="tags" href="/tags/XuNiJi.html" title=虚拟机>虚拟机会根据类的名称找到.class="tags" href="/tags/CLASS.html" title=class>class文件并加载它。 
        // 当new Point()的时候加载这个类࿰c;用forName构造实例的时候也加载该类。 只加载一次 
        System.out.println("before new Point()"); 
        new Point(); 
        System.out.println("after new Point()"); 
        try { 
            Class.forName("Line"); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
 
        // 利用对象调用getClass()方法获取该对象的Class实例 
        Point pt = new Point(); 
        Class c1 = pt.getClass(); 
        System.out.println(c1.getName()); // 结果:Point 
 
        // 使用Class的静态方法forName()࿰c;用类的名字获取一个Class实例 
        try { 
            Class c2 = Class.forName("Point"); 
            System.out.println(c2.getName()); // 结果:Point 
            Point pp = (Point) c2.newInstance(); //一旦某个类型的Class对象已经被加载到内存࿰c;就可以用它来产生该类型的所有对象。 
                                        //newInstance()调用类中缺省的构造方法。 
            pp.output(); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
 
        // 运用.class="tags" href="/tags/CLASS.html" title=class>class的方式获取Class实例(类) 
        Class c3 = Point.class="tags" href="/tags/CLASS.html" title=class>class; 
        System.out.println(c3.getName()); // 结果:Point 
 
        // 运用.calss的方式获取Class实例(基本类型) 
        Class c4 = int.class="tags" href="/tags/CLASS.html" title=class>class; 
        System.out.println(c4.getName()); // 结果:int 
 
        // 运用.class="tags" href="/tags/CLASS.html" title=class>class的方式获取Class实例(基本数据类型的封装类) 
        Class c5 = Integer.TYPE; 
        System.out.println(c5.getName()); // 结果:int 
        Class c6 = Integer.class="tags" href="/tags/CLASS.html" title=class>class; 
        System.out.println(c6.getName()); // 结果:class="tags" href="/tags/JAVA.html" title=java>java.lang.Integer 
    } 
} 
 
class="tags" href="/tags/CLASS.html" title=class>class Point { 
    static { 
        System.out.println("loading point"); 
    } 
 
    void output() { 
        System.out.println("x=" + x + ",y=" + y); 
    } 
    int x, y; 
} 
 
class="tags" href="/tags/CLASS.html" title=class>class Line { 
    static { 
        System.out.println("loading Line"); 
    } 
}code>


cle>

http://www.niftyadmin.cn/n/1332004.html

相关文章

Android切换Activity时的淡入动画和缩小动画

原文地址&#xff1a;http://blog.csdn.net/xiaochun91103/article/details/6199120 一、淡入效果&#xff1a; /anim/fade.xml内容如下&#xff1a; <?xml version"1.0" encoding"utf-8"?> <alpha xmlns:android"http://schemas.androi…

这份简历竟然值50w年薪?

面试官&#xff1a;用过哪些 Map我&#xff1a;LinkedHashMap、TreeMap面试官&#xff1a;说一说这两个 Map 的区别我&#xff1a;ConcurrentHashMap 线程安全&#xff0c;TreeMap 可以自定义排序面试官&#xff1a;ConcurrentHashMap 怎么保证线程安全我&#xff1a;……面试官…

编程大佬是否能记住代码,不用百度就能啪啪啪敲出来么?

点击上方“果汁简历”&#xff0c;选择“置顶公众号”有位新接触编程的新手在知乎上提问[1]&#xff1a;想知道那些编程大佬是不是代码都能记住&#xff0c;然后不用查百度就能啪啪啪打出来呢&#xff1f;从大一接触编程到现在一直在练习代码&#xff0c;但是很多函数和库还是没…

Java IO简介

Java 流在处理上分为字符流和字节流。 字符流处理的单元为 2 个字节的 Unicode 字符&#xff0c;分别操作字符、字符数组或字符串&#xff1b; 字节流处理单元为 1 个字节&#xff0c;操作字节和字节数组。 ( 一 )以字节为导向的流------InputStream/OutputStream 以字节为…

为啥查询那么慢?

1. MySQL查询慢是什么体验&#xff1f;大多数互联网应用场景都是读多写少&#xff0c;业务逻辑更多分布在写上。对读的要求大概就是要快。那么都有什么原因会导致我们完成一次出色的慢查询呢&#xff1f;1.1 索引在数据量不是很大时&#xff0c;大多慢查询可以用索引解决&#…

计算机方面经典书籍一

我的另一篇博客共享了一些优秀的书籍的电子版&#xff0c;参见 《计算机编程优秀书籍电子版共享&#xff08;持续更新……&#xff09;》 图灵教育官方博客&#xff1a;http://turingbooks.iteye.com/ Windows经典书籍 CSDN博客&#xff1a;http://blog.csdn.net/dadalan…

SpringBoot中的线程池,你真的会用么?

点击上方“果汁简历”&#xff0c;选择“置顶公众号”前言前两天做项目的时候&#xff0c;想提高一下插入表的性能优化&#xff0c;因为是两张表&#xff0c;先插旧的表&#xff0c;紧接着插新的表&#xff0c;一万多条数据就有点慢了后面就想到了线程池ThreadPoolExecutor&…

解决CRT(即C Run-Time)中函数的安全警告

解决CRT&#xff08;即C Run-Time&#xff09;中函数的安全警告 参考MSDN 1、Security Features in the CRT 2、Secure Template Overloads 是不是有时候碰到这样的警告&#xff1a; warning C4996: strcpy: This functionor variable may be unsafe. Consider using strc…