gpt4 book ai didi

java - 'java.io.ObjectOutputStream' 已弃用 - Intellij IDEA 中的错误

转载 作者:行者123 更新时间:2023-11-30 10:34:21 25 4
gpt4 key购买 nike

我有这个代码:

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 类是删除线 像这样: screenshot。将鼠标指针指向上方时 - 出现此消息:'java.io.ObjectOutputStream' is deprecated。什么意思?

当我运行此代码时,IntelliJ 打开“编辑配置”窗口,要求我介绍 VM 选项。但我将其留空并继续运行。

最佳答案

IntelliJ IDEA 有一个意向操作,使用 External Annotations 将库类注释为已弃用支持。您可能是意外触发了此意图操作。

annotate

对于以这种方式弃用的类,应该有相反的操作:Deannotate,但它可能不起作用(bug reported)。

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

更新:Deannoate 操作现在应该可以工作,但只能在带注释的类本身内部进行,而不是来自其引用。

关于java - 'java.io.ObjectOutputStream' 已弃用 - Intellij IDEA 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41684382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com