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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:16:02+00:00 2026-05-12T16:16:02+00:00

Quickie pseudo-aesthetics question: For field declarations, the following is allowed: int i, j, k;

  • 0

Quickie pseudo-aesthetics question:

For field declarations, the following is allowed:

int i, j, k;

providing three variables for integers. Does anything similar exist for method declarations, ala:

public int getI() {/* ... */},
getJ() {/* ... */},
getK() {/* ... */};

so that the method accessibility, return type, etc don’t have to be redundantly specified? I can imagine some cases where this sort of syntax would seem really beneficial (e.g., methods with an assortment of argument sets allowed), so I’m hoping it’s in there somewhere. I’ve tried the above, and it doesn’t seem to work.

EDIT: relative to KLE’s question about needs, there isn’t a requirement, it’s more about wants. The most annoying thing I’m facing is that I have a class of a bunch algorithms that are static (and should be static, as they don’t depend on anything but their arguments) but take a generic argument with some restrictions. The restrictions are the same for every method, and it really uglies up the code to have to repeat them for every method, but putting them in the class definition (i.e., public class Foo<U extends Bar>) seems to preclude making the methods static.

ALSO: Can someone elaborate on why using sharing the fields declaration is considered bad practice? I think I can appreciate that perspective in the commercial application realm, but it seems a little strange in the scientific application realm – sharing types fields seems an obvious and simple means of indicating when things should be the same kind of thing.

  • 1 1 Answer
  • 1 View
  • 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-12T16:16:02+00:00Added an answer on May 12, 2026 at 4:16 pm

    It is considered bad form for fields, especially once generics are involved. Consider this (real world case) of pre generic code:

    private Map a = new HashMap(), b = new HashMap();
    

    Now a and b had different contents (their generic types would be different). This was java 1.3/1.4 code, so it didn’t matter. But now, when I have to add generics, that has to be split apart, and it becomes a more involved change. The declaration of int i, j; would probably not exist if not for the fact that C/C++ has them.

    So for your method declarations, sure it saves some boilerplate, but at the sacrifice of readability and maintainability. Readability in the sense that the declaration could be tens or hundreds of lines away from the rest of the method. Maintainability in terms of what if one of those methods in the middle of that chain had to change their generic type? Now you have a whole bunch of code that has to be moved around, and you have to get those commas right.

    Now this isn’t the biggest deal, especially with a modern IDE, but the bottom line is really is that Java is just not terse language, and it values expressiveness and clarity over concise expression.

    In some cases, that hurts DRY, but in this case the fact that these methods have the same return type is simply coincidental and it isn’t a true repetition to re-declare them.

    Anyway, a macro expansion, if anything, would be a more appropriate way to solve this problem (not that Java is getting that any time soon).

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

Sidebar

Related Questions

Just a quickie ... I have the following ID generator strategy for one of
Quickie question: I'm toying with some of the new taskbar APIs in Windows 7
Quickie-Question: To summarize, I'm a little confused as to how I would design such
A quickie just to get peace of mind: Considering the following final String str
Just a quickie, i have an xml resource in res/values/integers.xml <?xml version=1.0 encoding=utf-8?> <resources>
A quickie, and hopefully an easy one. I'm following the docs at http://docs.djangoproject.com/en/dev/topics/auth/ to
I am writing a quickie BlackJack Winforms app to demonstrate a couple of concepts.
Just a quickie before the weekend rolls in... I have a Method with the
Just a quickie.. If I set on an alert document.title to ALERT per say.
Hopefully this is a quickie: I've been doing a lot of Java/Google Web Toolkit

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.