【发布时间】:2017-05-31 18:19:16
【问题描述】:
我有这个代码:
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 错误。
-
Java 8 中已弃用的项目列表:Deprecated list
-
@Vusal,谢谢你的链接。但是
ObjectOutputStream类不在此列表中。 -
是的。我发现只有
java.io.ObjectOutputStream.PutField.write(ObjectOutput)已弃用。 -
java.io.ObjectOutputStream已不被弃用,任何另有说明的工具都是在骗你。
标签: java intellij-idea deprecated objectoutputstream