Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6370995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:00:11+00:00 2026-05-25T01:00:11+00:00

I seem to be having some sort of an issue suppressing a warning that

  • 0

I seem to be having some sort of an issue suppressing a warning that I get from deserializing an ArrayList containing type MyObject, from file. The error message I am getting is from the line

objects = (ArrayList<MyObject>) ois.readObject();

It reads:

Type safety: Unchecked cast from Object to ArrayList<MyObject>

After I apply the @SuppressWarnings(“unchecked”) to the specific warning, it says that my objects object cannot be resolved to a type.

ArrayList<MyObject> objects;
try {
    FileInputStream fis = new FileInputStream(new File("myfile.txt"));
    ObjectInputStream ois = new ObjectInputStream(fis);
    @SuppressWarnings("unchecked")
    objects = (ArrayList<MyObject>) ois.readObject(); //Getting 'objects cannot be resolved to a type'
    fis.close();
}

catch (Exception e) {
    objects = new ArrayList<MyObject>();
}

This is very strange because if I apply @SuppressWarnings(“unchecked”) to the entire method, the error goes away. Also, it IS occurring on multiple machines, not just on one setup.

Does anyone have any insight as to what is going on that makes this error appear when I suppress only the one instance of the error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:00:11+00:00Added an answer on May 25, 2026 at 1:00 am

    @SupressWarnings("unchecked") can only be applied to the declariation of the object, this will work:

    @SuppressWarnings("unchecked")
    ArrayList<String> objects = (ArrayList<String>) ois.readObject();
    

    … but may not solve your problem. The reason for this can be found in the JDK source code. The @Target annotation on the @SupressWarnings annotation defines the permitted locations:

    @Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seem to be having an issue with std::auto_ptr and assignment, such that the object
Seem to be having some issues storing the current date in a core data
I seem to be having some problems with dbExpress in Delphi XE2. When I
I've having some troubles with the PDO bindValue() function. Whenever I seem to use
I'm having a bizarre issue that I haven't seen before and I'm thinking it
I must be having some sort of google-block today, because I can't find an
I am using aspx controls from dev express. The issue I am having is
I seem to be having some extremely odd cache_money interactions. When I am on
Having some odd behavior I'd love some feed back on as I can't seem
I seem to be having a very frustrating time with an inherited class calling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.