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

  • Home
  • SEARCH
  • 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 9248529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:57:52+00:00 2026-06-18T09:57:52+00:00

In the past I often used import static construct in Java classes. Recently I

  • 0

In the past I often used “import static” construct in Java classes. Recently I realized that instead of

import static my.pack.A.MY_CONSTANT;

you can use

import my.pack.A;

public class B {
    private static final MY_CONSTANT = A.MY_CONSTANT;
}

The most obvious advantages of this approach are:

  1. You can use refactoring in Eclipse to easily strip out all long constant expressions like A.B.C.CONSTANT.ANOTHER_ONE.TOO_LONG from your code without messing with static imports (which are not so quick to master in Eclipse)
  2. You can give any name to any expression, which may be more meaningful in the current context.

For example:

private static final PAYMENT_TYPE = PaymentType.CASH;
...
calculateSomething(amount, PAYMENT_TYPE);

instead of

import static my.pack.PaymentType.CASH
...
calculateSomething(amount, CASH);

and also this is more easy to refactor, if the default PaymentType value changes to CREDIT_CARD.

My question is: are there any downsides of this approach compared to static imports or can it be used everywhere instead?

My only concern for now is the resulting compiled .class file, which is probably different for the two described approaches. So performance and memory usage may theoretically suffer.

  • 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-18T09:57:53+00:00Added an answer on June 18, 2026 at 9:57 am

    I think the only downside is you have more code where you assign one constant to another constant. Other than that there should be no difference. Performance and memory shouldn’t matter, you’ll likely have more references back to the same constant pool entries. Even if it created separate constant pool entries it would take a lot of them to make a difference.

    Being able to give good names to constants might be a very good thing, in cases where it isn’t feasible to rename the original entries.

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

Sidebar

Related Questions

In the past I've heard that it can be dangerous to rename the Plone
in the recent past i’ve noticed quite often that, when searching something with google
I've used other systems like Starteam in the past and patches created using that
Question I often see it stated that rules should be avoided and triggers used
Looking back at my past projects I often encounter this one: A client or
In past, I am using Listview and using below code can show a particular
In the past it was my understanding that the Lat/Lon of an airport had
In the past I have used MAPISendMail to launch Outlook (or whatever the desired
There is this simple function which I have used with C++ in the past
I am contracting at a company that uses MKS. I have used SVN 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.