# 反编译并查看 Scala 代码的字节码

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/idea/llms.txt).

> **TL;DR**
> 必需插件：   Scala  ： [安装方法](get-started-with-scala.html#scala_plugin)

IntelliJ IDEA 允许您将 Scala 编译器生成的字节码反编译为 Java，并直接检查字节码。

Procedure: 安装必需插件

此功能依赖于   Java 字节码反编译器   和   字节码查看器   插件，这些插件在 IntelliJ IDEA 中默认捆绑并启用。

如果相关功能不可用，请确保您未禁用这些插件。

1. 按 `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) 打开设置，然后选择  `插件` 。

2. 找到   Java 字节码反编译器   和   字节码查看器   插件，然后点击   启用  。 如果出现提示，请重启 IDE。

Procedure: 以 Java 显示反编译的类

1. 通过点击主菜单中的  `构建 | 构建项目`  或按 `Ctrl+F9` (Windows), `⌘ F9` (macOS), `⌘ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ B` (macOS System Shortcuts), `Ctrl+F9` (XWin), `Ctrl+F9` (GNOME), `Ctrl+9` (KDE), `Ctrl+F9` (Emacs), `Ctrl+F9` (Sublime Text), `Ctrl+F9` (Sublime Text (macOS)), `F7` (Visual Studio), `F7` (Visual Studio (macOS)), `F11` (NetBeans), `Ctrl+F9` (Eclipse), `⌘ B` (Eclipse (macOS)) 构建项目。 或者，通过按 `Shift+F10` (Windows), `⌃ R` (macOS), `⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌥ ⇧ R` (macOS System Shortcuts), `Shift+F10` (XWin), `Shift+F10` (GNOME), `Shift+F10` (KDE), `Shift+F10` (Emacs), `Shift+F10` (Sublime Text), `Shift+F10` (Sublime Text (macOS)), `Ctrl+F5` (Visual Studio), `⌃ F5` (Visual Studio (macOS)), `F6` (NetBeans), `Alt+Shift+X` (Eclipse), `⌘ ⇧ F11` (Eclipse (macOS)) 运行项目。

2. 在   项目   工具窗口（ `Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Ctrl+1` (NetBeans), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))）中，打开  `target`  文件夹，右键点击要反编译的  `.class`  文件，然后选择   将反编译的类显示为 Java  。

3. 反编译的代码将显示在编辑器中。

![将反编译的类显示为 Java](https://resources.jetbrains.com/help/img/idea/2026.3/scala_decompileasjava.png)

从 [Java 字节码反编译器](decompiler.html) 页面了解更多信息。

Procedure: 显示字节码

1. 通过点击主菜单中的  `构建 | 构建项目`  或按 `Ctrl+F9` (Windows), `⌘ F9` (macOS), `⌘ F9` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ B` (macOS System Shortcuts), `Ctrl+F9` (XWin), `Ctrl+F9` (GNOME), `Ctrl+9` (KDE), `Ctrl+F9` (Emacs), `Ctrl+F9` (Sublime Text), `Ctrl+F9` (Sublime Text (macOS)), `F7` (Visual Studio), `F7` (Visual Studio (macOS)), `F11` (NetBeans), `Ctrl+F9` (Eclipse), `⌘ B` (Eclipse (macOS)) 构建项目。 或者，通过按 `Shift+F10` (Windows), `⌃ R` (macOS), `⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌥ ⇧ R` (macOS System Shortcuts), `Shift+F10` (XWin), `Shift+F10` (GNOME), `Shift+F10` (KDE), `Shift+F10` (Emacs), `Shift+F10` (Sublime Text), `Shift+F10` (Sublime Text (macOS)), `Ctrl+F5` (Visual Studio), `⌃ F5` (Visual Studio (macOS)), `F6` (NetBeans), `Alt+Shift+X` (Eclipse), `⌘ ⇧ F11` (Eclipse (macOS)) 运行项目。

2. 在   项目   工具窗口（ `Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Ctrl+1` (NetBeans), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))）中，选择一个类、case 类、对象、case 对象或枚举文件。

3. 在主菜单中，前往  `视图 | 显示字节码` 。 IntelliJ IDEA 将显示一个包含字节码的对话框。

![显示字节码](https://resources.jetbrains.com/help/img/idea/2026.3/scala_bytecode_viewer.png)

反编译器的功能存在一些限制：

* 您想要查看的字节码应存在：项目应成功编译，且您选择的文件应在使用中，因为编译器有时会在编译过程中忽略无效代码。

* 您选择的文件应仅包含一个类、case 类等。

* 反编译器不会显示包含顶级定义的 Scala 文件的字节码。

从 [显示已编译文件的字节码](bytecode-viewer.html) 了解更多信息。

## See also

### 相关

[Java Bytecode Decompiler](decompiler.html) [Project tool window](project-tool-window.html)

