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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:28:42+00:00 2026-06-09T00:28:42+00:00

I have a problem which isn’t really that big, but still gives me some

  • 0

I have a problem which isn’t really that big, but still gives me some thought as to how Java constructors and methods are used.

I have a constant representing a radius I declare final, and also make it public for everyone to see. I don’t want my code littered with getRadius() methods when I’m never ever going to change the radius.

I want to initialize the constant within the constructor as I want to apply certain criteria before assigning the radius, certain conditions have to be met. However, these conditions do take up some space, and I’d like to put them in some other method, to make the constructor cleaner.

The whole thing would initially look like this

public MyProblematicClass {
   public final int radius;
   public MyProblematicClass(... variables ...) {
      if(... long criteria ...) {
         radius = n;
      }
   }
}

and I’d love it to end up like

public MyProblematicClass {
       public final int radius;
       public MyProblematicClass(... variables ...) {
          this.setRadiuswithCriteria(criteria);
}

private void setRadiuswithCriteria(criteria crit) {
   if(... crit ...) {
      radius = n;
   }

I understand that I could potentially use the method for other purposes and that’s the reason for giving me a ‘blank field RADIUS may not have been initialized, so I’d like to know if there is a way to add a method which will only be used in constructors, for cleanliness’s sake.

  • 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-09T00:28:45+00:00Added an answer on June 9, 2026 at 12:28 am

    How about (using small caps for radius, because it is not a constant, as pointed out in the comments):

    public MyProblematicClass(... variables ...) {
        radius = getRadiusWithCriteria(criteria);
    }
    
    private int getRadiusWithCriteria(criteria crit) {
       if(... crit ...) {
          return n;
       } else {
          return 0;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a problem which seems simple at first, but really isn't. I'm storing
I have a function which isn't so complicated, but for some reason, each time
I have a problem which I don't really know how to solve. I have
I have a design problem which I would like some input on. Here are
So my problem is that I have a NSManagedObject 'A' which has a has-many
(This is not exactly the problem that I have, but it's isomorphic, and I
I'm thinking about a problem which has some similarity with perfect forwarding, but where
I have a problem which makes me crazy. I think it is very easy
I have a problem which requires a reversable 1:1 mapping of keys to values.
I have a problem which I cant seem to find answer to through searches

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.