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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:10:50+00:00 2026-06-11T11:10:50+00:00

import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.Injector; public class GuiceDemo { public static

  • 0
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;

public class GuiceDemo
{
    public static void main(String[] args)
    {
        new GuiceDemo().run();
    }

    public void run()
    {
        Injector injector = Guice.createInjector(new EmptyModule());
        DemoInstance demoInstance = injector.getInstance(DemoInstance.class);
        assert(demoInstance.demoUnbound == null);
    }

    public static class EmptyModule extends AbstractModule
    {
        @Override
        protected void configure()
        {
        }
    }

    public static class DemoInstance
    {
        public final DemoUnbound demoUnbound;

        @Inject
        public DemoInstance(DemoUnbound demoUnbound)
        {
            this.demoUnbound = demoUnbound;
        }
    }

    public static class DemoUnbound
    {
    }
}

Can I prevent Guice from providing an instance of DemoUnbound to the constructor of DemoInstance?

In essence I am looking for a way to run Guice in a totally explicit binding mode where injecting an unbound class is an error.

How do you make it an error to Guice inject a class not bound in the Module?

  • 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-11T11:10:51+00:00Added an answer on June 11, 2026 at 11:10 am

    If you use an interface here instead of a concrete class for DemoUnbound, Guice will throw an exception because it cannot find a suitable class to inject:

    public class GuiceDemo
    {
        public static void main(String[] args)
        {
            new GuiceDemo().run();
        }
    
        public void run()
        {
            Injector injector = Guice.createInjector(new EmptyModule());
            DemoInstance demoInstance = injector.getInstance(DemoInstance.class);
            assert(demoInstance.demoUnbound == null);
        }
    
        public static class EmptyModule extends AbstractModule
        {
            @Override
            protected void configure()
            {
            }
        }
    
        public static class DemoInstance
        {
            public final DemoUnbound demoUnbound;
    
            @Inject
            public DemoInstance(DemoUnbound demoUnbound)
            {
                this.demoUnbound = demoUnbound;
            }
        }
    
        public interface DemoUnbound
        {
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I met a problem when trying @Singleton of Guice: import com.google.inject.Singleton; @Singleton public class
import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import android.os.Bundle; public class Map2Activity extends MapActivity { /** Called
In my GWT app I have the following model class: import com.google.gwt.user.client.rpc.IsSerializable; public class
In the following minimalistic example: import com.google.gson.Gson; import com.google.gson.GsonBuilder; public class GsonStuff { public
Activity where I want to use: import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; public class BankoTinklasMap extends
Code: import com.independentsoft.exchange.Service; import android.app.Activity; import android.os.Bundle; public class ContactsToExchangeActivity extends Activity { @Override
I have the following code: import com.apple.dnssd.*; public interface IServiceAnnouncer { public void registerService();
import com.google.appengine.api.labs.taskqueue.Queue; import com.google.appengine.api.labs.taskqueue.QueueFactory; import static com.google.appengine.api.labs.taskqueue.TaskOptions.Builder.*; // ... Queue queue = QueueFactory.getDefaultQueue(); queue.add(url(/worker).param(key,
Please help me look into my simple test case: import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; import
I am trying to use http://code.google.com/p/as3svgrendererlib/ in my flash cs 5.5 project to import

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.