"incompatible types: unexpected return value"当我的方法不是无效并且有回报时



我正在尝试为我进入Java类的分配,此方法此方法从文本文件中读取一系列对象并返回它们,但是我遇到了不相容的类型:此方法上的意外返回值错误:

public readContacts(String fileName){
    Contact[] fileContents;
    try(ObjectInputStream fileIn = new ObjectInputStream(
    new FileInputStream(fileName)))
    {
        while (true)
        {
            fileContents = (Contact[]) fileIn.readObject();
            return fileContents;
        }
    }
    catch (EOFException e)
    {}
    catch (Exception e)
    {}
}

我看到的这个错误的每个其他问题,有人将方法放在void put仍然输入返回值的情况下。显然,这在我的情况下不适用。

您没有指定函数的数据类型。

Contact [] readContacts(String fileName) {}

最新更新