Skip to content

Commit

Permalink
8263102: Expand documention of Method.isBridge
Browse files Browse the repository at this point in the history
Reviewed-by: smarks
  • Loading branch information
jddarcy committed Mar 10, 2021
1 parent d0c1aec commit 67ea3bd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -511,6 +511,7 @@ public boolean isVarArgs() {
/**
* {@inheritDoc}
* @jls 13.1 The Form of a Binary
* @jvms 4.6 Methods
* @since 1.5
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -518,6 +518,7 @@ public boolean isVarArgs() {
* construct as defined by
* <cite>The Java Language Specification</cite>.
* @jls 13.1 The Form of a Binary
* @jvms 4.6 Methods
*/
public boolean isSynthetic() {
return Modifier.isSynthetic(getModifiers());
Expand Down
43 changes: 38 additions & 5 deletions src/java.base/share/classes/java/lang/reflect/Method.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -567,12 +567,44 @@ public Object invoke(Object obj, Object... args)
}

/**
* Returns {@code true} if this method is a bridge
* method; returns {@code false} otherwise.
* {@return {@code true} if this method is a bridge
* method; returns {@code false} otherwise}
*
* @return true if and only if this method is a bridge
* method as defined by the Java Language Specification.
* @apiNote
* A bridge method is a {@linkplain isSynthetic synthetic} method
* created by a Java compiler alongside a method originating from
* the source code. Bridge methods are used by Java compilers in
* various circumstances to span differences in Java programming
* language semantics and JVM semantics.
*
* <p>One example use of bridge methods is as a technique for a
* Java compiler to support <i>covariant overrides</i>, where a
* subclass overrides a method and gives the new method a more
* specific return type than the method in the superclass. While
* the Java language specification forbids a class declaring two
* methods with the same parameter types but a different return
* type, the virtual machine does not. A common case where
* covariant overrides are used is for a {@link
* java.lang.Cloneable Cloneable} class where the {@link
* Object#clone() clone} method inherited from {@code
* java.lang.Object} is overridden and declared to return the type
* of the class. For example, {@code Object} declares
* <pre>{@code protected Object clone() throws CloneNotSupportedException {...}}</pre>
* and {@code EnumSet<E>} declares its language-level {@linkplain
* java.util.EnumSet#clone() covariant override}
* <pre>{@code public EnumSet<E> clone() {...}}</pre>
* If this technique was being used, the resulting class file for
* {@code EnumSet} would have two {@code clone} methods, one
* returning {@code EnumSet<E>} and the second a bridge method
* returning {@code Object}. The bridge method is a JVM-level
* override of {@code Object.clone()}. The body of the {@code
* clone} bridge method calls its non-bridge counterpart and
* returns its result.
* @since 1.5
*
* @jls 8.4.8.3 Requirements in Overriding and Hiding
* @jls 15.12.4.5 Create Frame, Synchronize, Transfer Control
* @jvms 4.6 Methods
*/
public boolean isBridge() {
return (getModifiers() & Modifier.BRIDGE) != 0;
Expand All @@ -590,6 +622,7 @@ public boolean isVarArgs() {
/**
* {@inheritDoc}
* @jls 13.1 The Form of a Binary
* @jvms 4.6 Methods
* @since 1.5
*/
@Override
Expand Down

1 comment on commit 67ea3bd

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.