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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:59:17+00:00 2026-06-05T14:59:17+00:00

I ran into a simple issue naively trying to do this: public void someMethod(){

  • 0

I ran into a simple issue naively trying to do this:

public void someMethod(){    
  int x = 0;
  ...
  @SuppressWarnings({"rawtypes", "unchecked"})
  x = ((Comparable)lhs).compareTo(rhs);
  ...
}

This is illegal and has to be rephrased to compile:

public void someMethod(){  
  ...  
  @SuppressWarnings({"rawtypes", "unchecked"})
  int x = ((Comparable)lhs).compareTo(rhs);
  ...
}

I have traced the issue down to ElementType : a statement doesn’t seem to be a valid program element. This is rather confusing – I thought that a statements is something like a supertype of all programming elements.

  1. Is there a theoretical or a technical reason for the restriction of valid elements?

  2. Could it be done differently – i.e. supposed I could supplant ElementType with my own class and master the rippling changes, could I annotate any statement?

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

    If you look at the Javadoc for @SuppressWarnings you’ll see the answer: its declared targets are

    @Target(value={TYPE,FIELD,METHOD,PARAMETER,CONSTRUCTOR,LOCAL_VARIABLE})
    

    In other words, it cannot be legally applied to a statement. It can, however, be applied to a variable declaration. It has nothing to do with whether a statement is a program element; it is basically because this annotation applies only to declarations of things.

    Furthermore, if you look at the Javadoc for the enumeration that describes things that can have annotations, statements and expressions are not among the choices. In general, annotations can be applied to declarations of things, not to bits of code.

    The theoretical reason for this is just that annotations are stored as properties of individual items declared in the class file. Statements don’t qualify; by the time your code is compiled, statements have ceased to exist. There is only a stream of bytecode, and the only reminder of the statements it came from are the (optional) line number tables. To deal with this, they’d need to add a new attribute to the class file to reference the individual bytecodes, as in this proposal, and deal with a number of complexities that arise as a result.

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

Sidebar

Related Questions

Ran into this error message while trying to select some records off a table.
Edit: it's been ages since I've ran into this "issue" back then, and by
I just ran into an issue while trying to write an bitmap-manipulating algo for
Ran into an Out of Stack Space error trying to serialize an ASP.Net AJAX
I ran into a strange issue over the weekend while I was working on
I ran into this error when building my code with CLANG: In file included
I ran into something a little odd this morning and thought I'd submit it
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
Ok, so I've ran into a very strange issue, directly connected with before blocks.
Ok I've just ran into this and I was only supposed to be checking

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.