java中的静态类 - 心得
发布日期:2021-06-30 16:57:16
浏览次数:2
分类:技术文章
本文共 1021 字,大约阅读时间需要 3 分钟。
心得1
- 静态内部类 和 非静态内部类 的区别在于,前者可以绕过外部类直接构造,而后者不行
public class Outer { static class StaticInner { } class Inner{ } public static void main(String[] args) { new Outer.StaticInner(); //new Outer.Inner(); // 这样写会报错 new Outer().new Inner(); //需要先new Outer,才能new Inner }}
- 基于上面的现象,可以理解为:非静态内部类是外部类的一部分,而静态内部类与外部类相对独立(既:调用时,不需要有外部类即可有静态内部类)。
- 此外,静态内部类和外部类以外的类的区别在于: ??不关心。。
- 因此,当外部类需要多个数据独立的内部类时(比如:LinkedList和Node),适合使用静态内部类。
重点:
这个文章→《从源码角度彻底搞懂LinkedList》心得2
有时候,内部类需要静态,是因为有静态方法需要调用它
public class Demo_geni { static int i = Q.i; static class Q{ static int i ; }}
心得3
或者它有静态属性
package cn.edut.com.tarena;import org.junit.Test;public class Test2 { @Test public void test001() { new T1().start(); while (true) { int t = T1.get(); if(t%2==1) { System.out.println(t); System.exit(0); } } } static class T1 extends Thread{ static int i ; public static int get() { return i; } @Override public void run() { while (true) { i++; i++; } } }}
转载地址:https://lawsssscat.blog.csdn.net/article/details/102942298 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月15日 01时33分04秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
NeoFetch - Linux 使用命令行查看系统信息
2019-04-30
Jenkins 控制台输出中的奇怪字符
2019-04-30
Linux添加系统调用
2019-04-30
ubuntu 18 CTF 环境搭建
2019-04-30
linux内存的寻址方式
2019-04-30
[off by null + tcache dup]lctf_easy_heap
2019-04-30
[pie+libc]national2021_pwny
2019-04-30
task_struct 结构分析
2019-04-30
Linux创建进程的源码分析
2019-04-30
ubunut16.04的pip3出现问题,重新安装pip3
2019-04-30
how2heap-double free
2019-04-30
how2heap-fastbin_dup_consolidate
2019-04-30
orw_shellcode_模板
2019-04-30
[fmt+shellcode]string
2019-04-30
fmt在bss段(neepusec_easy_format)
2019-04-30
[double free] 9447 CTF : Search Engine
2019-04-30
python 函数式编程
2019-04-30
python编码
2019-04-30