Skip to content

Commit 67ea3bd

Browse files
committed
8263102: Expand documention of Method.isBridge
Reviewed-by: smarks
1 parent d0c1aec commit 67ea3bd

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

src/java.base/share/classes/java/lang/reflect/Constructor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -511,6 +511,7 @@ public boolean isVarArgs() {
511511
/**
512512
* {@inheritDoc}
513513
* @jls 13.1 The Form of a Binary
514+
* @jvms 4.6 Methods
514515
* @since 1.5
515516
*/
516517
@Override

src/java.base/share/classes/java/lang/reflect/Executable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -518,6 +518,7 @@ public boolean isVarArgs() {
518518
* construct as defined by
519519
* <cite>The Java Language Specification</cite>.
520520
* @jls 13.1 The Form of a Binary
521+
* @jvms 4.6 Methods
521522
*/
522523
public boolean isSynthetic() {
523524
return Modifier.isSynthetic(getModifiers());

src/java.base/share/classes/java/lang/reflect/Method.java

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -567,12 +567,44 @@ public Object invoke(Object obj, Object... args)
567567
}
568568

569569
/**
570-
* Returns {@code true} if this method is a bridge
571-
* method; returns {@code false} otherwise.
570+
* {@return {@code true} if this method is a bridge
571+
* method; returns {@code false} otherwise}
572572
*
573-
* @return true if and only if this method is a bridge
574-
* method as defined by the Java Language Specification.
573+
* @apiNote
574+
* A bridge method is a {@linkplain isSynthetic synthetic} method
575+
* created by a Java compiler alongside a method originating from
576+
* the source code. Bridge methods are used by Java compilers in
577+
* various circumstances to span differences in Java programming
578+
* language semantics and JVM semantics.
579+
*
580+
* <p>One example use of bridge methods is as a technique for a
581+
* Java compiler to support <i>covariant overrides</i>, where a
582+
* subclass overrides a method and gives the new method a more
583+
* specific return type than the method in the superclass. While
584+
* the Java language specification forbids a class declaring two
585+
* methods with the same parameter types but a different return
586+
* type, the virtual machine does not. A common case where
587+
* covariant overrides are used is for a {@link
588+
* java.lang.Cloneable Cloneable} class where the {@link
589+
* Object#clone() clone} method inherited from {@code
590+
* java.lang.Object} is overridden and declared to return the type
591+
* of the class. For example, {@code Object} declares
592+
* <pre>{@code protected Object clone() throws CloneNotSupportedException {...}}</pre>
593+
* and {@code EnumSet<E>} declares its language-level {@linkplain
594+
* java.util.EnumSet#clone() covariant override}
595+
* <pre>{@code public EnumSet<E> clone() {...}}</pre>
596+
* If this technique was being used, the resulting class file for
597+
* {@code EnumSet} would have two {@code clone} methods, one
598+
* returning {@code EnumSet<E>} and the second a bridge method
599+
* returning {@code Object}. The bridge method is a JVM-level
600+
* override of {@code Object.clone()}. The body of the {@code
601+
* clone} bridge method calls its non-bridge counterpart and
602+
* returns its result.
575603
* @since 1.5
604+
*
605+
* @jls 8.4.8.3 Requirements in Overriding and Hiding
606+
* @jls 15.12.4.5 Create Frame, Synchronize, Transfer Control
607+
* @jvms 4.6 Methods
576608
*/
577609
public boolean isBridge() {
578610
return (getModifiers() & Modifier.BRIDGE) != 0;
@@ -590,6 +622,7 @@ public boolean isVarArgs() {
590622
/**
591623
* {@inheritDoc}
592624
* @jls 13.1 The Form of a Binary
625+
* @jvms 4.6 Methods
593626
* @since 1.5
594627
*/
595628
@Override

0 commit comments

Comments
 (0)