Browse Source

Introduce ApplicationContextEvent.getSource() with covariant return type

Prior to this commit, ApplicationContextEvent inherited getSource()
from java.util.EventObject.getSource() which has an Object return type.

This commit introduces a local getSource() implementation in
ApplicationContextEvent with an ApplicationContext covariant return
type, analogous to TestContextEvent in spring-test.

Closes gh-35197
pull/34323/merge
Sam Brannen 5 months ago
parent
commit
5c6622fd77
  1. 21
      spring-context/src/main/java/org/springframework/context/event/ApplicationContextEvent.java

21
spring-context/src/main/java/org/springframework/context/event/ApplicationContextEvent.java

@ -20,9 +20,10 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
/** /**
* Base class for events raised for an {@code ApplicationContext}. * Base class for events raised for an {@link ApplicationContext}.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Sam Brannen
* @since 2.5 * @since 2.5
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
@ -30,7 +31,7 @@ public abstract class ApplicationContextEvent extends ApplicationEvent {
/** /**
* Create a new {@code ApplicationContextEvent}. * Create a new {@code ApplicationContextEvent}.
* @param source the {@code ApplicationContext} that the event is raised for * @param source the {@link ApplicationContext} that the event is raised for
* (must not be {@code null}) * (must not be {@code null})
*/ */
public ApplicationContextEvent(ApplicationContext source) { public ApplicationContextEvent(ApplicationContext source) {
@ -38,10 +39,22 @@ public abstract class ApplicationContextEvent extends ApplicationEvent {
} }
/** /**
* Get the {@code ApplicationContext} that the event was raised for. * Get the {@link ApplicationContext} that the event was raised for.
* @return the {@code ApplicationContext} that the event was raised for
* @since 7.0
* @see #getApplicationContext()
*/
@Override
public ApplicationContext getSource() {
return getApplicationContext();
}
/**
* Get the {@link ApplicationContext} that the event was raised for.
* @see #getSource()
*/ */
public final ApplicationContext getApplicationContext() { public final ApplicationContext getApplicationContext() {
return (ApplicationContext) getSource(); return (ApplicationContext) super.getSource();
} }
} }

Loading…
Cancel
Save