A bridge method may be created by the compiler when extending a parameterized type whose methods have parameterized arguments.
You can find in this class BridgeMethodResolver a way to get the actual Method referred by a 'bridge method'.
See Create Frame, Synchronize, Transfer Control:
As an example of such a situation, consider the declarations:
class C<T> { abstract T id(T x); }
class D extends C<String> { String id(String x) { return x; } }
Now, given an invocation
C c = new D();
c.id(new Object()); // fails with a ClassCastException
The erasure of the actual method being invoked, D.id(String)
differs in its signature from that of the compile-time method declaration, C.id(Object)
. The former takes an argument of type String while the latter takes an argument of type Object. The invocation fails with a ClassCastException before the body of the method is executed.
Such situations can only arise if the program gives rise to an unchecked warning (§5.1.9).
Implementations can enforce these semantics by creating bridge methods. In the above example, the following bridge method would be created in class D:
Object id(Object x) { return id((String) x); }
This is the method that would actually be invoked by the Java virtual machine in response to the call c.id(new Object())
shown above, and it will execute the cast and fail, as required.
See also Bridge:
as mentioned in the comment, bridge methods are also needed for covariant overriding:
- In Java 1.4, and earlier, one method can override another if the signatures match exactly.
- In Java 5, a method can override another if the arguments match exactly but the return type of the overriding method, if it is a subtype of the return type of the other method.
Typically, a method Object clone()
can be overridden by a MyObject clone()
, but a bridge method will be generated by the compiler:
public bridge Object MyObject.clone();
相关推荐
This paper shows how a Monte Carlo valuation method may be used with the NIG process, incorporating stratified sampling together with an inverse Gaussian bridge. The method is illustrated by pricing ...
Bridge Separates an object’s interface from its implementation Composite A tree structure of simple and composite objects Decorator Add responsibilities to objects dynamically Facade A single...
Polya reveals how the mathematical method of demonstrating a proof or finding an unknown can be of help in attacking any problem that can be "reasoned" out - from building a bridge to winning a game ...
Chapter 2: A Case Study: Designing an App Chapter 3: Prototype Chapter 4: Factory Method Chapter 5: Abstract Factory Chapter 6: Builder Chapter 7: Singleton Chapter 8: Adapter Chapter 9: Bridge ...
• Bridge • Composite • Decorator • Facade • Flyweight • Proxy • Discussion of Structural Patterns Behavioral Patterns • Chain of Responsibility • Command • Interpreter • ...
Different types of damage on the bridge of the numerical model are simulated and transient analyses are performed by incorporating a load which moves constantly along the beam nodes. Continuous ...
This is a method to learn and to refer back later. The author recommends to read and review the book several times. It is easy to grasp but powerful when repeated the second time around.
This book will help you bridge that testing gap between your developers and your testers by giving your team a model to discuss automated testing, and most importantly, to coordinate their efforts. ...
Is the book a bridge to some new topics of research?” The influence of functional analysis and Bourbakism has been clear for a long time. At the same time, numerical methods emerged from analysis. ...
Learn how to implement design patterns in Java: each pattern in Java Design Patterns ...Chapter 22: Bridge Patterns (Or Handle/Body Patterns) Chapter 23: Visitor Patterns Chapter 24: Interpreter Patterns
Rainald Löhner introduces the reader to the techniques required to achieve efficient CFD solvers, forming a bridge between basic theoretical and algorithmic aspects of the finite element method and ...
• Chapter 10: The Bridge Pattern • Chapter 11: The Abstract Factory Pattern • Chapter 12: How Do Experts Design? • Chapter 13: Solving The CAD/CAM Problem with Patterns • Chapter 14: The ...
To this end, we propose a novel and efficient crossdomain human parsing model to bridge the cross-domain differences in terms of visual appearance and environment conditions and fully exploit ...
The design is made by the H-bridge topology with the use of MOSFET as a switch. The simulation for the system constructed with the help of MATLAB/SIMULINK. The SPWM method improves the efficiency and...
This book was conceived as a method of helping pharmacists and prescribers to 'bridge the gap' between the acquisition of theoretical knowledge about drugs and its practical application to individual...
longer released before a blocking operation during control method execution. This effectively makes the AML Interpreter single- threaded. The overhead of a semaphore per-method is eliminated. Fixed a...
Bridge Composite Decorator Facade Flyweight Private Class Data Proxy Behavioral patterns Chain of Responsibility Command Interpreter Iterator Mediator Memento Null Object Observer State Strategy ...
// An example method that takes a comma-separated list of numbers and returns the array rpc ExampleMethod ( TestMessage ) returns ( TestMessage ); } message MyRequest { string message = 1 ; } ...
This helps ensure the bridge functions properly during a long service life and guards against catastrophic failure under extreme events. Although these systems have achieved some success, this ...
A novel method of producing optimum switching functions for the voltage and harmonic control of DC-to-AC bridge inverters using neural networks is presented. Results obtained an experimental ...