Skip to content

Commit 5c6622f

Browse files
committed
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
1 parent 096670f commit 5c6622f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,41 @@
2020
import org.springframework.context.ApplicationEvent;
2121

2222
/**
23-
* Base class for events raised for an {@code ApplicationContext}.
23+
* Base class for events raised for an {@link ApplicationContext}.
2424
*
2525
* @author Juergen Hoeller
26+
* @author Sam Brannen
2627
* @since 2.5
2728
*/
2829
@SuppressWarnings("serial")
2930
public abstract class ApplicationContextEvent extends ApplicationEvent {
3031

3132
/**
3233
* Create a new {@code ApplicationContextEvent}.
33-
* @param source the {@code ApplicationContext} that the event is raised for
34+
* @param source the {@link ApplicationContext} that the event is raised for
3435
* (must not be {@code null})
3536
*/
3637
public ApplicationContextEvent(ApplicationContext source) {
3738
super(source);
3839
}
3940

4041
/**
41-
* Get the {@code ApplicationContext} that the event was raised for.
42+
* Get the {@link ApplicationContext} that the event was raised for.
43+
* @return the {@code ApplicationContext} that the event was raised for
44+
* @since 7.0
45+
* @see #getApplicationContext()
46+
*/
47+
@Override
48+
public ApplicationContext getSource() {
49+
return getApplicationContext();
50+
}
51+
52+
/**
53+
* Get the {@link ApplicationContext} that the event was raised for.
54+
* @see #getSource()
4255
*/
4356
public final ApplicationContext getApplicationContext() {
44-
return (ApplicationContext) getSource();
57+
return (ApplicationContext) super.getSource();
4558
}
4659

4760
}

0 commit comments

Comments
 (0)