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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:01:29+00:00 2026-05-26T10:01:29+00:00

I was wondering why when I use an anonymous instanciation along with an instance

  • 0

I was wondering why when I use an anonymous instanciation along with an instance initializer block, I get a “serializable class does not declare a static final serialVersionUID field of type long” compile-time warning.

Here’s what I mean. Let’s say I want to instantiate an ArrayList and at the same time add something to it like so:

ArrayList<Object> arrayList = new ArrayList<Object>(){{add(new Object());}}; 

If I compile this all is ok but I get the serialVersionUID field missing warning. Now ArrayList already implements serializable and has a private static final long serialVersionUID so why is it that when I use it like that it seems that that field “dissapears” and I get a warning for not having it declared?

  • 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-26T10:01:29+00:00Added an answer on May 26, 2026 at 10:01 am

    When you create your anonymous class, you are actually extending ArrayList and therefore, inheriting the Serializable interface.

    All Serializable classes are supposed to have a serialVersionUID so that you can distinguish between different serialized versions of the classes. Since the anonymous type is a new class, it would be a good idea to give it an ID so you can distinguish between different versions of it.

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

Sidebar

Related Questions

I was wondering how to use cin so that if the user does not
I am wondering when to use static methods? Say if I have a class
Does anyone know if you can use data binding with anonymous types in Silverlight
I was wondering what use an rvalue reference member has class A { //
Just wondering when you use multiple classes on the one element such as class=foo
I was wondering how PHP handles an anonymous array, if I make use of
I'm wondering can I use static libraries (lib*.a files) compiled with one version of
Studying compilers course, I am left wondering why use registers at all. It is
I'm wondering how to use a VideoDisplay object (defined in MXML) to display video
I am wondering how to use NUnit correctly. First, I created a separate test

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.