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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:48:57+00:00 2026-05-28T13:48:57+00:00

I started exploring Google Guice today to do dependency injection in my application. I

  • 0

I started exploring Google Guice today to do dependency injection in my application.

I noticed I am not using @Inject annotation anywhere. But it’s working. Can not understand this concept. In this example, where @Inject is the best fit in my scenerio? If any one can point me out.

public interface Tweeter {
    public void sendTweet(String message);
}

public class SmsTweeter implements Tweeter {
    @Override
    public void sendTweet(String message) {
        System.out.println("You SMS tweet: "+message);
    }
}

import com.google.inject.AbstractModule;

public class TweetModule extends AbstractModule{

    @Override
    protected void configure() {
        bind(Tweeter.class).to(SmsTweeter.class);       
    }
}

import com.google.inject.Guice;
import com.google.inject.Injector;

public class TestTweetClient {
    public static void main(String[] args) {
        Injector injector = Guice.createInjector(new TweetModule());
        Tweeter tweeter = injector.getInstance(Tweeter.class);
        tweeter.sendTweet("Hi there");
    }
}

It prints (the hidden implementation works):
You SMS tweet: Hi there

  • 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-28T13:48:58+00:00Added an answer on May 28, 2026 at 1:48 pm

    There is no best fit for @Inject in your example. The class SmsTweeter has an implicit zero-args constructor. You could make it explicit and add @Inject there but it is not necessary.

    public class SmsTweeter implements Tweeter {
    
        @Inject
        SmsTweeter() {
            // nothing to do
        }
    
        @Override
        public void sendTweet(String message) {
            System.out.println("You SMS tweet: "+message);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We started using Google Maps on our web application rather extensively. It worked fine
I have recently started exploring Maven, but I feel a bit overwhelmed of all
I started an application in Google App Engine right when it came out, to
I've recently started exploring using AJAX for a small project, and I've had reasonable
today I discovered the wonderful world of CMS and decided to started exploring this
Started with this question: OpenID. How do you logout OK. So OpenID does not
I started using subversion for one of my projects and it would be absolutely
Just started exploring Cocoa so pretty much a total noob. I've written a very
I have just started exploring TWILL . Twill is an amazing scripting language for
I just started exploring Java Servlets and JSP and am a little confused about

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.