---
title: "java编译器的聪明"
author: "yanlei3032"
date: "2012-03-23T15:37:44Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2012-03-23T15:37:44Z"
id: 1462530
url: "https://dls.iteye.com/blog/1462530"
---

代码 如下 ：

 

```
public class TestStatic
{
    
    public static void main(String[] args)
    {
        TestStatic1 test = null;
        System.out.println(test.ss);
    }
}

class TestStatic1
{
    static String ss = "1223";
    
    Set set=new HashSet();
}
```

 想象中的结果：报控制正异常。

 实际结果 ：打印出1223.

 

   反编译之后的结果 ：

```
import java.io.PrintStream;

public class TestStatic
{
  public static void main(String[] args)
  {
    TestStatic1 test = null;
    System.out.println(TestStatic1.ss);
  }
}
```

 

  编译器自动对这种不合理的方式进行了优化。