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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:00:28+00:00 2026-06-11T18:00:28+00:00

Consider a fairly basic service: class KeepANumberService extends Service { // The codes used

  • 0

Consider a fairly basic service:

class KeepANumberService extends Service {
    // The codes used in incoming messages
    final static int REQUEST_SET_NUMBER = 0;
    final static int REQUEST_GET_NUMBER = 1;

    // The information this service works with internally
    int numberToKeep = 0;

    // The handler for incoming messages
    private IncomingMessageHandler incomingMessageHandler = new IncomingMessageHandler();

    // Start up and close down stuff
    < Insert standard start up and close down code OnCreate, OnBind etc etc here >

    void returnNumber(Messenger destination) {
         Message msg = <construct message with numberTo>;
         destination.send(msg);
    }

    // Handler that receives messages from the thread
    private class IncomingMessageHandler extends Handler {

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case REQUEST_SET_NUMBER:
                numberToKeep = msg.whatever; // get data from wherever it's hidden in the msg
                break;
            case REQUEST_GET_NUMBER:
                returnNumber(msg.replyTo);
                break;
            } 
          }
      }
  }

}

Now, if I am developing this in eclipse with lint running, I have a choice between two options at present:

  1. The code as above will have a warning on the private final class IncomingMessageHandler line saying that it should be decalared as a static to ensure everything works at run time.
  2. If I make that class (IncomingMessageHandler) static, it can no longer access data and functions in the overall class (KeepANumberService), which is a pain (possibly impossible in some cases?) to code.

So, how important is it to make the message handler static? And why?

  • 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-11T18:00:29+00:00Added an answer on June 11, 2026 at 6:00 pm

    The keyword static, when used on inner class definitions, says that the inner class does not require a reference to the outer class. Usually you do this if the inner class is a “data container” (think “struct in C”). In your case, your inner class is not a data container, it is simply a private inner class that has methods and requires access to the member variables of the outer class. So there is absolutely no reason to declare this class static. That would be counterproductive.

    Looking at your code I have no idea why you get a warning to declare this class static. Just ignore it.

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

Sidebar

Related Questions

Consider the following code: template <class x1, class x2 = int*> struct CoreTemplate {
I consider myself fairly versatile when it comes to O/S selection. I have used
Consider the following C#: // C# .net switch(x) { case 1: for(int i =
Consider a class like this one: class MyReferenceClass { public: MyReferenceClass(); const double ImportantConstant1;
Consider a class that is supposed to make parameter suggestion, given some clues, and
I have a problem building a fairly simple local CGO project. Consider this very
I consider myself fairly competent in understanding and manipulating C-ish languages; it's not a
I'm fairly familiar with most aspects of web development and I consider myself a
I'm running a fairly typical LAMP stack with PHP running through mod_fcgid. I'd consider
I would consider myself a fairly competent programmer with experience in Java and VB.net.

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.