当前位置:网站首页>Give priority to static member classes
Give priority to static member classes
2022-06-22 08:26:00 【ambition_ forever】
Internal class type : Static member classes 、 Non static member class 、 An anonymous class 、 Local class , It is equivalent to the auxiliary class of the inner class .
public class StaticOrNoClass {
// Static member classes
static class A {
public static String a = "123";
}
// Non static member class
class B {
public String b = "789";
}
private static String a = "456";
private static String s1 = "s1";
private String s2 = "s2";
public static void main(String[] args) {
// 1、 Static inner class
System.out.println(E02.A.a);
System.out.println(A.a);
System.out.println(E02.a);
System.out.println(a);
// 2、 Share static variables
E02 e021 = new E02();
E02 e022 = new E02();
System.out.println(e022.s1);
e021.s1 = "s22";
System.out.println(e022.s1);
// 3、 Non static inner class belongs to instance , You need to instantiate the external class first , Then instantiate the inner class , Binding between inner and outer classes , influence GC
B b = e021.new B();
b.b = "hahha";
System.out.println(b.b);
// 4、 An anonymous class
new Thread(()->{
System.out.println("1");
}).start();
// 5、 Inner class
LinkedHashMap<String, String> m1 = new LinkedHashMap();
LinkedHashMap<String, String> m2 = new LinkedHashMap(){
@Override
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > 2;
}
};
m1.put("a", "a");
m1.put("b", "b");
m1.put("c", "c");
m1.put("d", "d");
m2.put("a", "a");
m2.put("b", "b");
m2.put("c", "c");
m2.put("d", "d");
System.out.println(m1.size());
System.out.println(m2.size());
System.out.println(m1);
System.out.println(m2);
}
}
边栏推荐
- Preview function implementation of Android kotlin Camera2
- Coding complexity C (n)
- Five skills to be an outstanding cloud architect
- Top ten of the year! Saining network security was once again shortlisted in the top 100 report on China's digital security
- Multiple ways for idea to package jars
- 复杂科学在创客教学研究中的应用
- Questions 1 to 100 of the national information security grade examination nisp level 1 question bank (1)
- Questions 101 to 200 of the national information security grade examination nisp level 1 question bank (1)
- Submit values of various inputs of the form
- Detailed sorting of Oracle and MySQL pages
猜你喜欢

每周推荐短视频:什么是“计算世界”?

PostgreSQL source code (56) extensible type analysis expandedobject/expandedrecord

Example of QT qtableview

steam教育文化传承的必要性

复杂科学在创客教学研究中的应用

Web Knowledge 1 (server +servlet)

Mt4/mql4 getting started to be proficient in EA tutorial lesson 7 - common functions of MQL language (VII) - index value taking function
On Fresnel phenomenon

Interview shock 59: can there be multiple auto increment columns in a table?

Any to Any 实时变声的实现与落地丨RTC Dev Meetup
随机推荐
PostgreSQL source code (56) extensible type analysis expandedobject/expandedrecord
QT custom composite control (class promotion function)
Summary of sub database and sub table 1
Interview shock 59: can there be multiple auto increment columns in a table?
Mt4/mql4 getting started to proficient in foreign exchange EA automatic trading tutorial - special identification of the K line on the chart
DTD约束
Is pioneer futures safe? What are the procedures for opening futures accounts? How to reduce the futures commission?
矩阵运算
C # interface holding structure causes packing problem
每周推荐短视频:什么是“计算世界”?
Enumerations, custom types, and swaggerignore in swagger
Bee framework, an ORM framework that can be learned in ten minutes --bee
The necessity of steam education culture inheritance
Questions 101 to 200 of the national information security grade examination nisp level 1 question bank (1)
The jdbcurl is configured correctly in the project, but the jdbcurl is the wrong path after the project is started
Powerful database design tool PowerDesigner
Web knowledge 4 (filter+listener)
How to troubleshoot OOM
Idea reports an error "insufficient memory"
DTD constraints