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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:46:26+00:00 2026-05-23T08:46:26+00:00

Here’s the scenario: I have a program that contains an annotation that I built

  • 0

Here’s the scenario:

I have a program that contains an annotation that I built out in my eclipse project, it’s called ‘flag’.
The ‘flag’ annotation has an ‘id’ element
I have a method in my class called ‘connect’ that establishes a socket connection.
I annotate the connect method by placing the ‘flag’ annotation before it and give it an ‘id’

public class Foo {
   @flag(id = 'slowConnection')
   public boolean connect() {
      // connect logic here...
   }
}

Now, what I ultimately want is something like the following

public class Foo {
   @flag(id = 'slowConnection')
   public boolean connect() {
      // connect logic here...
   }

   @flag(id = 'mediumConnection')
   public boolean connect() {
      // medium connection logic here
   }

   @flag(id = 'fastConnection')
   public boolean connect() {
      // fast connection logic here
   }
}

Allow me to elaborate here. My objective is to be able to only include the correct ‘connect’ method at compile time based on an input parameter to the class. Method overloading is a similar way to do this, albeit I don’t want to change the method signature. I’m also aware that inheritance would be a way to do this. Eclipse (rightly so) complains when I have the above code, saying that there’s a duplicate method. Is there anyway that I could proceed with the above in Eclipse before I compile the program as I will perform some logic to strip out all but one of the ‘connect’ methods before the program is compiled? Is there a way to automatically disable auto-compilation in eclipse? Any tips or pointers would be helpful.

  • 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-23T08:46:27+00:00Added an answer on May 23, 2026 at 8:46 am

    You move the connection logic to a separate interface and then use the factory pattern to generate the appropriate connection:

    public interface IFoo {
       void connect();
    }
    
    final class SlowFoo implements IFoo {
      //Implementation for slow connections
    } 
    
    final class MediumFoo implements IFoo {
      //Implementation for medium connections
    } 
    
    final class FastFoo implements IFoo {
      //Implementation for fast connections
    } 
    

    If the classes share common code, you should consider introducing a base class like FooBase.

    The factory could then look like this:

    public final class FooFactory {
       public IFoo create() {
          if (Connection.speed < 100) //Fictive value
              return new SlowFoo();
          if (Connection.speed < 1000) //Fictive value
              return new MediumFoo();
    
          return new FastFoo();
       }
    }
    

    Messing around with the source code before compilation is not a good idea IMHO.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here is what I am trying to achieve in PHP: I have this string:
Here is another spoj problem that asks how to find the number of distinct
I have just tried to save a simple *.rtf file with some websites and
Basically, what I'm trying to create is a page of div tags, each has
I have a jquery bug and I've been looking for hours now, I can't
here are 2 screen shots when i try to debug my code in visual
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:

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.