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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:59:44+00:00 2026-05-23T14:59:44+00:00

Having this class Class Test { static int version=1; String A; String B; //constructor

  • 0

Having this class

Class Test
{ 
  static int version=1;
  String A;
  String B;

  //constructor
  //setters, getters, etc...      
  public void printAll(void)
  {
     System.out.println(A);
     System.out.println(B);
  }    
}

After a while, we modify the Class to add a String C :

Class Test
{ 
  static int version=2;
  String A;
  String B;
  String C;

  //constructor
  //setters, getters, etc...      
  public void printAll(void)
  {
     System.out.println(A);
     System.out.println(B);
     //it seems somebody has forgotten to print C!!!!!!!!!

  }    
}

Is here some known approach to avoid this kind of bug?

Thanks

  • 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-05-23T14:59:45+00:00Added an answer on May 23, 2026 at 2:59 pm

    You can use annotations to have a more structured way to use reflection, where you better control which fields will be printable:

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.FIELD})
    @interface Printable { }
    
    class Test {
    
      @Printable String A;
      @Printable String B;
      @Printable String C;
    
      public void printAll() {
        for (Field field : getClass().getDeclaredFields()) {
          if (field.isAnnotationPresent(Printable.class)) {
            try {
              System.out.println(field.get(this));
            } catch (Exception e) {
              throw new RuntimeException(e);
            }       
          }
        }
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Program { public delegate void VoidMethodDelegate(); public delegate int IntMethodDelegate(); static void Main(string[]
i am having a strange problem, i have a static class like this public
I have this following test code: public static final String[] list = { apple,ball,cat,dog,egg,fan,girl,hat,igloo,jerk
The title isn't very clear but I'll try to explain. Having this class: class
There are many classes having this provider suffix. (Data,membership,modelmetadata,...). When should be a class
Having a snippet like this: import yaml class User(object): def __init__(self, name, surname): self.name=
I need to add and delete class on an element having multiple classes: This
I have a div having a css class MyClass. Inside this div, I can
I'm having some problems with this piece of code. I've included a class declaration
I'm having trouble declaring a const field in an abstract class. Why is this?

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.