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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:59:54+00:00 2026-05-24T21:59:54+00:00

Can I have an annotation for a method that when its parameters are null,

  • 0

Can I have an annotation for a method that when its parameters are null, just do nothing, effectively as not being invoked?

  • 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-24T21:59:55+00:00Added an answer on May 24, 2026 at 9:59 pm

    Probably the easiest way to do this is using interfaces and dynamic proxies. Annotations do nothing other than add metadata. You’re going to have to add code to act based on the annotation.

    You’d have to do a few things —

    Create an interface

    public interface IService {
    
         @ValidateNull // Your custom annotation
         public void yourMethod(String s1);
    }
    

    When using the implementation, instantiate it as a JDK Proxy.

    IService myService = (IService)java.lang.Proxy.newInstance(ServiceImpl.class.getClassLoader(),
                               ServiceImpl.class.getInterfaces(), 
                               new YourProxy(new ServiceImpl());
    

    Now, you can via reflection, capture all invocations of your method in YourProxy class.

     public YourProxy implements InvocationHandler {
    public Object invoke(Object arg0, Method method, Object[] args) throws Throwable {
        if (method.isAnnotationPresent(ValidateNull.class)) {
                       //Check args if they are null and return.
                }
         }
     }
    

    If you dont want to do this, then you’re looking at more heavyweight frameworks such as AspectJ / Spring AOP.

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

Sidebar

Related Questions

I have written a java annotation that looks like this: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) // can
Routines can have parameters, that's no news. You can define as many parameters as
I have a program that can have a lot of parameters (we have over
I have an element that can have multiple types (not my design). The element
I have a variable in code that can have file path or url as
I have a phone number field that can have lots of different characters such
I have noticed in Java that you can have a function with object... as
In my application I have listener that is reading annotations from model files (just
I have a C# annotation which is : [AttributeUsage(AttributeTargets.Method)] public class OperationInfo : System.Attribute
When obtaining a TypeElement in an annotation processor, you can ask for its super

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.