'java.io.ObjectOutputStream' 已弃用 - Intellij IDEA 中的错误 [英] 'java.io.ObjectOutputStream' is deprecated - an error in Intellij IDEA

查看:57
本文介绍了'java.io.ObjectOutputStream' 已弃用 - Intellij IDEA 中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

import java.io.FileOutputStream;导入 java.io.IOException;导入 java.io.ObjectOutputStream;导入 java.util.Date;公共类雇员处理器{公共静态无效主(字符串 [] args){员工员工=新员工();员工.lastName = "史密斯";员工.firstName = "亚当";员工 ID = 123456789;员工工资 = 50000;try(FileOutputStream fileOutStr = new FileOutputStream("Employee.ser");ObjectOutputStream objectOutStr = new ObjectOutputStream(fileOutStr)) {objectOutStr.writeObject(员工);System.out.println("员工被外化到文件Employee.ser");} catch (IOException ioError){ioError.printStackTrace();}}}

但在 Intellij IDEA ObjectOutputStream 类中是删除线 像这样:

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

要手动修复它,请在 annotations.xml 文件"nofollow noreferrer">SDK 注释选项卡 并编辑/删除它.

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

I have this code:

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();
        }
    }
}

But in Intellij IDEA ObjectOutputStream class is strikethrough Like this: screenshot. When pointing mouse pointer over - this message appears: 'java.io.ObjectOutputStream' is deprecated. What does it mean?

When I run this code, IntelliJ opens "Edit Configurations" windows asking me to introduce VM options. But I leave it blank and run anyway.

解决方案

IntelliJ IDEA has an intention action to annotate library classes as Deprecated using the External Annotations support. You've probably triggered this intention action by accident.

For the classes deprecated this way there supposed to be the reverse action: Deannotate, but it may not work (bug reported).

To fix it manually, find the annotations.xml file in a directory that is configured in the SDK Annotations tab and edit/remove it.

UPDATE: Deannoate action should work now, but only while inside the annotated class itself, not from its reference.

这篇关于'java.io.ObjectOutputStream' 已弃用 - Intellij IDEA 中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆