GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update serialization part in Java基础知识.md · zjtech/JavaGuide@387abcd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs/java/basis
    • Java基础知识.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/java/basis/Java基础知识.md‎

Copy file name to clipboardExpand all lines: docs/java/basis/Java基础知识.md
+7-2Lines changed: 7 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1348,9 +1348,14 @@ try (BufferedInputStream bin = new BufferedInputStream(new FileInputStream(new F
13481348

13491349
### Java 序列化中如果有些字段不想进行序列化,怎么办?
13501350

1351-
对于不想进行序列化的变量,使用`transient`关键字修饰。`
1351+
对于不想进行序列化的变量,使用 `transient` 关键字修饰。
13521352

1353-
`transient` 关键字的作用是:阻止实例中那些用此关键字修饰的的变量序列化;当对象被反序列化时,被 `transient` 修饰的变量值不会被持久化和恢复。`transient` 只能修饰变量,不能修饰类和方法。
1353+
`transient` 关键字的作用是:阻止实例中那些用此关键字修饰的的变量序列化;当对象被反序列化时,被 `transient` 修饰的变量值不会被持久化和恢复。
1354+
1355+
关于 `transient` 还有几点注意:
1356+
- `transient` 只能修饰变量,不能修饰类和方法。
1357+
- `transient` 修饰的变量,在反序列化后变量值将会被置成类型的默认值。例如,如果是修饰 `int` 类型,那么反序列后结果就是 `0`。
1358+
- `static` 变量因为不属于任何对象(Object),所以无论有没有 `transient` 关键字修饰,均不会被序列化。
13541359

13551360
### 获取用键盘输入常用的两种方法
13561361

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.