不推荐使用’java.io.ObjectOutputStream’ – Intellij IDEA中的错误

我有这个代码:

import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.Date; public class EmployeeProcessor { public static void main(String[] args) { Employee employee = new Employee(); employee.lastName = "Smith"; employee.firstName = "Adam"; employee.id = 123456789; employee.salary = 50000; try(FileOutputStream fileOutStr = new FileOutputStream("Employee.ser"); ObjectOutputStream objectOutStr = new ObjectOutputStream(fileOutStr)) { objectOutStr.writeObject(employee); System.out.println("An employee is externalized into the file Employee.ser"); } catch (IOException ioError){ ioError.printStackTrace(); } } } 

但是在Intellij IDEA中ObjectOutputStream类是strikethrough像这样: 截图 。 将鼠标指针指向时 – 会显示以下消息: 'java.io.ObjectOutputStream' is deprecated 。 这是什么意思?

当我运行此代码时,IntelliJ打开“编辑配置”窗口,要求我引入VM选项。 但是我把它留空并且无论如何都要跑。

IntelliJ IDEA有一个意图操作,使用External Annotations支持将库类注释为Deprecated。 你可能偶然触发了这个意图行动。

注释

对于以这种方式弃用的类,应该采取相反的操作:Deannotate,但它可能不起作用( 报告错误 )。

要手动修复它,请在SDK Annotations选项卡中配置的目录中找到annotations.xml文件,然后编辑/删除它。

更新 :Deannoate操作现在应该可以工作,但仅限于带注释的类本身,而不是来自其引用。