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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:03:05+00:00 2026-06-13T12:03:05+00:00

Please i want to serialize a several type of array to kwon what is

  • 0

Please i want to serialize a several type of array to kwon what is the worst on memory. So i create a function to serialize a generic type int calcul(T a) and it return a size on int.

public class NewClass<T> {
    public static void main(String[] args) throws IOException {
       byte[] tabByte = new byte[56666];
       Byte[] tabByte2 = new Byte[56666];
       int[] tabInt = new int[56666];
       ArrayList<Byte> arr=new ArrayList<Byte>(56666);  

       System.out.println("size array byte[]"+calcul(tabByte));
       System.out.println("size array Byte[]"+calcul(tabByte2));
       System.out.println("size array int[]"+calcul(tabInt));
       System.out.println("size array ArrayList<Byte>"+calcul(arr));
    }


    static int calcul(T a) throws IOException {
        ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
        ObjectOutputStream stream = new ObjectOutputStream(byteOutput);
        stream.writeObject(a);
        int a =  byteOutput.toByteArray().length;
        stream.flush();
        stream.close();
        byteOutput.flush();
        byteOutput.close();    

        return a;
    }

}

But i have this error

non-static type variable T cannot be referenced from a static context 

How can i do to make a generic variable as static and run my program ?

  • 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-06-13T12:03:06+00:00Added an answer on June 13, 2026 at 12:03 pm

    What are the generics for? I think you want

     static int calcul(Serializable a) throws IOException;
    

    And you should take the length after you flush and close the streams.

    And to answer your original question, you can do calculations (and read up here) about the memory requirements of primitive and wrapped ArrayLists and arrays (but the experiment should be instructive, too).

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

Sidebar

Related Questions

I want to change my question. please let me know what's happening; type is
I want to store a 4-byte int in a char array... such that the
Please see this fiddle I want the scrolling div stop following when left div
please help me. I want know about what types of flags to run an
I just want to show text please wait while app is searching for satellite
I want to Integrate Weather radar on my MapView.Please anyone help on doing this
Could someone please explain when would I want to use delegation instead of inheritance?
I want to add background image to uinavigationcontroller. Please help me.
Please find the code at http://jsfiddle.net/wlogeshwaran/NGL8P/4/ Here i want to make the 'hi' ,
I want obtain full URL adres in php script, tell please, this code always

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.