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 3787676
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:52:42+00:00 2026-05-19T11:52:42+00:00

I have a question because I’m getting a little confused (or maybe I’m not

  • 0

I have a question because I’m getting a little confused (or maybe I’m not noticing something obvious). Let’s say that I’ve got some source code that contains a lot of classes which contain a great number of static fields defined like this one:

public final class ConverterTYPE  {
    private final static HashMap<String, Byte> STRING_MAP = new HashMap<String, Byte>() {
        {
            put("A", new Byte((byte)12));
            put("B", new Byte((byte)13));
        }
    };

}

As we all know, static fields are not going to be serialized.

However, Java (and Eclipse) complains that “The serializable class does not declare a static final serialVersionUID field of type long”. Why can’t they notice that static is not going to be serialized?

And the next question: would it be a right solution to this issue to use @SuppressWarnings("serial") to get rid of all such warnings?

EDIT:

None of my classes implements Serializable interface (or none of their superclasses). And Eclipse is pointing at HashMap<String, Byte> with its warnings. Why doesn’t it detect that it’s static field?

  • 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-19T11:52:42+00:00Added an answer on May 19, 2026 at 11:52 am

    Just because that field may not be serialized doesn’t mean the thing it references will never itself be serialized! Someone/thing else could get a reference to that map and try to serialize it directly, or use it as an instance member in a serializable class, etc.I see it is private, but making sure it will never be accessed outside the current class or set to an instance member is beyond the scope of the compiler (and impossible with reflection around anyway).

    One possible solution is to simply avoid that anonymous subclass w/ initializer style all together and do this:

    private final static HashMap<String, Byte> STRING_MAP = new HashMap<String, Byte>();
    
    static {  
      STRING_MAP.put("A", new Byte((byte)12));
      STRING_MAP.put("B", new Byte((byte)13));
    }
    

    The result is close to identical in most cases and your code isn’t peppered with anonymous classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I rephrased the question because I have not explained well. Let's see if
This is not generic question. I have asked this question because I'm confused with
I have this question because I am not familiar latest generation of MS VS
I was reading this question (which you do not have to read because I
This is not exactly a straight-out question because I have just solved it, but
I'm asking this question because I finally solved a problem that I have been
My general question is, say you have a SQL Server 2005 database that's 20G
Out of fear that someone will downvote this question because piracy is not preventable,
I have to ask this question because I'm stuck, and I think its because
I am re-hashing this question because I have looked at over 50 threads in

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.