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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:31:04+00:00 2026-06-14T12:31:04+00:00

In the Google Guava EventBusExplained page, I don’t understand when they say the following:

  • 0

In the Google Guava EventBusExplained page, I don’t understand when they say the following:

To listen for a common event supertype (such as EventObject or
Object)…
…in traditional Java events: not easy.

…with EventBus:
events are automatically dispatched to listeners of any supertype,
allowing listeners for interface types or “wildcard listeners” for
Object.

  1. What does it mean to listen for a common event supertype?
  2. When they mention EventObject , are they talking about java.util.EventObject?
  3. What does it mean to allow “listeners for interface types or “wildcard listeners” for Object”?
  • 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-14T12:31:05+00:00Added an answer on June 14, 2026 at 12:31 pm

    This has to do with the limitations of method-overloading and interfaces that Guava’s EventBus class can overcome.

    For interfaces, consider the following scenario:

    I have the same code that gets invoked for multiple forms of input. For example, a listener that listens to mouse events, key events, and focus events, but all methods do the same thing: repaint the source. This would mean that my code would look like this:

    public class BunchOfListeners implements MouseListener, KeyListener, FocusListener {
    
        @Override
        public void focusGained(FocusEvent e) {
            doSomething(e);
        }
    
        @Override
        public void focusLost(FocusEvent e) {
            doSomething(e);
        }
    
        @Override
        public void keyTyped(KeyEvent e) {
            doSomething(e);
        }
    
        @Override
        public void keyPressed(KeyEvent e) {
            doSomething(e);
        }
    
        @Override
        public void keyReleased(KeyEvent e) {
            doSomething(e);
        }
    
        @Override
        public void mouseClicked(MouseEvent e) {
            doSomething(e);
        }
    
        @Override
        public void mousePressed(MouseEvent e) {
            doSomething(e);
        }
    
        @Override
        public void mouseReleased(MouseEvent e) {
            doSomething(e);
        }
    
        @Override
        public void mouseEntered(MouseEvent e) {
            doSomething(e);
        }
    
        @Override
        public void mouseExited(MouseEvent e) {
            doSomething(e);
        }
    
        public void doSomething(EventObject e) {
            ((Component) e.getSource()).repaint();
        }
    }
    

    Notice how ugly this is? There are 10 different methods for this, when ultimately the only thing we care about is getting the source off the event (which is specified by EventObject, by the way, which is why they used that in their example) and calling repaint on it.

    With Guava’s EventBus, this gets super, super simple. All I need in my GuavaIsAwesome ComponentRepainter class is one method:

    public class ComponentRepainter {
    
        @Subscribe
        public void doSomething(EventObject e) {
            ((Component) e.getSource()).repaint();
        }
    }
    

    When you register this with an EventBus and later fire, say, a MouseEvent on it:

    EventBus eventBus = ... ;
    eventBus.register(new ComponentRepainter());
    

    And later:

    MouseEvent e = ... ;
    eventBus.post(e);
    

    This will call the doSomething method on ComponentRepainter because it will not only fire the event to @Subscribe methods with MouseEvent for the parameter, but also to any methods that have a parameter that is assignable from MouseEvent. In other words, because MouseEvent extends EventObject, Guava’s EventBus will pass it to anything that accepts EventObject. If we made doSomething accept Object, then we can get every event that’s posted to the EventBus, making it a sort of global listener (because everything in Java extends Object).

    The same thing applies to interfaces as well. If you pass a concrete implementation to EventBus of some interface, then @Subscribe methods that use the interface (as opposed to the concrete type) will be called. It’s much more flexible, and overcomes the “10 useless methods” approach.

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

Sidebar

Related Questions

I'm using the interface Predicate<T> from com.google.common.base (Google Guava) But I don't know how
In my Java code, I am using Guava's Multimap ( com.google.common.collect.Multimap ) by using
In my Java code, I am using Guava's Multimap ( com.google.common.collect.Multimap ) by using
I'm a newbie with google guava. I don't know when we should use Iterables
since version 10 guava offers com.google.common.eventbus.EventBus - a generic pub-sub facility. It is not
Google Guava provides nice helpers to implement equals and hashCode like the following example
The com.google.common.base.Function interface (from Google Guava ) defines apply as: @Nullable T apply(@Nullable F
I am using the Google Guava CacheBuilder to create a Cache instance. My code
I'm using google guava 12 and have a map: Map<OccupancyType, BigDecimal> roomPrice; I have
The Android compiler complains that Google Guava v12's ImmutableSortedSet doesn't have the methods, first()

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.