我有这个代码:
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' 已弃用
。这是什么意思?
当我运行此代码时,IntelliJ 打开“编辑配置”窗口,要求我引入 VM 选项。但我还是把它留空并运行。
最佳答案
IntelliJ IDEA 有一个意图操作,使用 External Annotations 将库类注释为已弃用。支持。您可能无意中触发了此意图操作。
对于以这种方式弃用的类,应该有相反的操作:Deannotate,但它可能不起作用( bug reported )。
要手动修复此问题,请在 SDK Annotations tab 中配置的目录中找到 annotations.xml
文件。并编辑/删除它。
更新:Deanoate 操作现在应该起作用,但只能在带注释的类本身内部起作用,而不是在其引用中起作用。
关于java - “java.io.ObjectOutputStream”已弃用 - Intellij IDEA 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41684382/