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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:10:48+00:00 2026-05-12T15:10:48+00:00

1) There is Somelib which is added as jar in SomeProject . 2) In

  • 0

1) There is Somelib which is added as jar in SomeProject.

2) In SomeProject there is the somePackage.SomeClass which implements SomeLib.SomeInterface.

3) SomeLib must be able to create somePackage.SomeClass instance without building SomeLib each time

How is it possible without using reflection? It’s impossible to write in SomeLib something like import somePackage.Someclass.

I’m using Netbeans.

PS I’m newbie to Java and I tried to be as clear as possible.

  • 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-12T15:10:48+00:00Added an answer on May 12, 2026 at 3:10 pm

    You just could add a hard-coded dependency, but you should avoid that at all costs if you are planning to re-use your library (and even if you don’t)

    Instead use this pattern:

    1. Create a factory for creating SomeInterface implementations in your library. (See Factory method pattern for more information)

    2. In SomeProject you have to register your SomeClass with that factory. You can use a static initializer in conjuction with Class.forName for that.

      public class SomeClass {
          static {
            SomeFactory.registerSomeImplementation(SomeClass.class)
          }
      }
      
      Class.forName("somePackage.SomeClass") // Alternative 1 
      SomeClass.class.getName();             // Alternative 2
      

      Both alternatives load the class and run the static initializer, but the second one offers some better refactoring opportunities.
      Don’t be confused with Class.forName: One of the other answers suggested using it for creating a SomeClass instance in the library. But here you use it in the project for loading the class and thus running the static initializer.

    3. SomeLib then can use the factory to create an instance for SomeInterface.

      SomeInterface si = SomeFactory.createSomeObject();
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are few apps like Strava which records users movements using GPS. It also
There are several shading languages available today like GLSL, HLSL, CG, which one to
There's a bug in FireBug: I accidentally clicked where the line numbers are, which
There is probably an easy answer for this, but when I added DateTime.Now.ToString() to
There is an application written in PHP which I am converting to Ruby. When
There must be a simple solution to this, but after 4 hours of browsing
I have a class like: public class SomeClassImpl implements SomeClass { private static final
There are disassemblers like CFF explorer which display the AddressOfEntryPoint of any executable along
There is this SQL Statement SELECT t1.Name ,Count(t2.SubID) Totals -- I don't know how
There are numerous places on the Internet, suggesting that it is easily achieved by

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.