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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:38:34+00:00 2026-06-12T01:38:34+00:00

I have a basic question relating to the @SuppressWarnings(unused) annotation. Basically, I would like

  • 0

I have a basic question relating to the @SuppressWarnings("unused") annotation. Basically, I would like to suppress unused warnings on a block of code in my declarations section of my class. I would prefer not to suppress unused warnings on the entire class.

Currently, I am doing this:

public class MyClass {
    //Constants
    private final String ACCEPT = "Yes";
    @SuppressWarnings("unused")
    private final String DENY = "No";            //Not currently used
    private final String TENTATIVE = "Maybe";
    @SuppressWarnings("unused")
    private final String POSTPONE = "Later";     //Not currently used

    //Variables
    private int counter;
    ....

I find the above code to be a bit messy with the annotations thrown in randomly like that. What I would like to do is something like:

//Constants
@SuppressWarnings("unused")
{
  private final String ACCEPT = "Yes";
  private final String DENY = "No";            //Not currently used
  private final String TENTATIVE = "Maybe";
  private final String POSTPONE = "Later";     //Not currently used
}

//Variables
private int counter;
....

This is, of course, illegal in Java as a block cannot be simply made like this. Its not a huge deal or anything, but I am curious if I am missing an obvious and elegant solution.

  • 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-12T01:38:36+00:00Added an answer on June 12, 2026 at 1:38 am

    If you reeeeealy want to keep all those unused constants, a quick and dirty trick would be;

    public class MyClass {
    //Variables
        private int counter;
    
    @SuppressWarnings("unused")
        private static final class UnusedConstants{
            private final String ACCEPT = "Yes";
            private final String DENY = "No";            
            private final String TENTATIVE = "Maybe";
            private final String POSTPONE = "Later";     
       }
    }
    

    And i would make them static too, but your call.

    EDIT:
    Or, what i think is much nicer:

    public class MyClass {
    
        private enum Answer {
    
            ACCEPT ("Yes"),
            DENY ("No"),
            TENTATIVE("Maybe"),
            POSTPONE("Later");
    
            private final String answer;
    
            private Answer(String answer) {
            this.answer = answer;
            }
    
            public String toString() {
                return answer;
            }
        }
    }    
    

    This way you don’t get the unused warning as long as you use at least one of the values.

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

Sidebar

Related Questions

I have a basic question. I would like to make running Arc.py several times
I have a fairly basic question regarding python lists/dictionaries which I would like some
I'm just getting started in F# and have a basic question. Here's the code:
enter code hereI have a basic question regarding an implementation using a Axis2 web
I have a basic question about the form action. Consider the below code here,
I have BASIC logical question about the following code snippet: 1 uint64_t RMTileKey(RMTile tile)
I have a basic question on function pointer. In the below code snippet, how
I have a basic question for which I don't think attaching any code-snippet may
I have a basic question about implementing a Entity code first one to many
I have a basic question, in the Django template language how can you tell

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.