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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:43:25+00:00 2026-06-10T22:43:25+00:00

I want to create an annotation that restricts a developer from specifying null as

  • 0

I want to create an annotation that restricts a developer from specifying null as a parameter, which has been annotated with @NoNull

For example, if I create this method:

public void printLine(@NoNull String line) {
    System.out.println(line);
}

On a method call, I want an error to appear if the user specifies null for line: printLine(null);

I have been using APT for only a little bit of time, and am wondering how to do this (if possible)?

This is the annotation I have created so far:

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.SOURCE)
public @interface NoNull {}
  • 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-10T22:43:27+00:00Added an answer on June 10, 2026 at 10:43 pm

    Compile time will be tough to check, since you’re really dealing with runtime values. If you want to create annotations to automatically add code to check this stuff, you should look at project lombok:

    http://projectlombok.org/

    It uses an annotation processor to add code to your beans to do various things.

    For example:

    @Getter @Setter
    private int id;
    

    The annotation processor would automatically add get/set methods to your bean.

    I don’t think it has null checks, but you should be able to add this in and contribute it.

    Another option is to use the validation jsr, though this requires you to explicitly validate at runtime, but you could accomplish this with proxies or AOP.

    @NotNull @Min(1)
    public void setId(Integer id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create wordpress website into which I want create user management... That means
i want create a custom json data from the mssql 2008 results so that
I want to know if it is possible to create an Annotation that enforces
i want create multiple search where statement $where_search is a multiple condition from post
I want create module which update list of usb devices automatically (not only mass
I want to create a new field (or two) in my table that is
I want to create a Silverlight app to extract and manipulate data from an
I have a Java class which has some field annotated with @SearchCriteria(criteria = class1.class2.field)
I have been trying to create a Spring project that uses MyBatis for the
I'm trying to create a new annotation with which I'll do some runtime wiring,

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.