Java Compiler Method Reference Bridge Generation
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
In Java programming, event-handling mechanisms require programmers to define multiple classes for each user interface element and event type, leading to verbose and tedious code, as traditional approaches demand separate class definitions for each event type-user element pair.
Innovation Solution
A compiler modification that allows passing a reference to a method instead of an object, generating equivalent byte code by creating a 'bridge' class that implements the event-handling method, thus eliminating the need for separate class definitions and reducing code verbosity.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Ease of operation
If traditional EventListener interfaces are used in Java, then event handling functionality is achieved, but code verbosity increases and programming burden increases
Solution Approach 1:
The patent creates a copy of the functional behavior by generating a synthetic bridge class that implements the EventListener interface. This bridge class copies the essential functionality needed to handle events, allowing the programmer to work with method references directly while the compiler-generated class handles the interface requirements. This resolves the contradiction by maintaining the required interface structure without burdening the programmer with manual class definition.
Solution Approach 2:
The patent introduces an intermediary bridge class that mediates between the programmer's simplified method reference and the Java event handling system requiring full EventListener implementations. This intermediary automatically generated class translates the concise method reference into the full interface implementation that the Java system expects, thereby easing programming while maintaining system compatibility.
2Productivity
If separate classes are defined for each event type-user element pair, then proper event handling is achieved, but programming time increases and productivity decreases
Solution Approach 1:
The patent performs preliminary action by having the compiler automatically generate the bridge class definitions before runtime. Instead of requiring programmers to manually define classes for each event handling scenario, the compiler proactively creates the necessary class structures based on method references in the source code. This preliminary generation eliminates repetitive programming work and recovers programming time.
Solution Approach 2:
The patent enables self-service by allowing the compiler to automatically generate the event listener class implementations without programmer intervention. The system serves itself by using the method references provided in the code to automatically create the appropriate bridge classes, eliminating the need for programmers to manually write boilerplate class definitions for each event handler.
3Ease of operation
If method references are passed directly where object references are expected, then code conciseness is achieved, but compiler errors occur
Solution Approach 1:
The patent uses an intermediary bridge class to mediate between the method reference (what the programmer writes) and the object reference expectation (what the compiler requires). The bridge class serves as a translator that allows method references to be passed in simple syntax while the compiler sees and processes valid object references, thus maintaining both syntax simplicity and compilation reliability.
Solution Approach 2:
The patent creates a functional copy through the bridge class that implements the EventListener interface. This copied structure allows the method reference to be effectively copied into an object reference form that the compiler can process, maintaining type safety and compilation success while preserving the programmer's intent to use concise method references.
Data Source
AI summary
According to one embodiment of the invention, the JAVA compiler is modified so that when the JAVA compiler determines, while compiling source code, that an invocation of a first method, which expects to receive a reference to an object, passes, to the first method, a reference to a second method instead of a reference to an object, the JAVA compiler does not issue a compile-time error as the JAVA compiler normally would. Instead, the JAVA compiler generates compiled code (e.g., byte code) that the JAVA compiler would have generated if the source code had (a) defined a “bridge” class that implemented a method that invoked the second method and (b) contained, in the invocation of the first method, a reference to an object that was an instance of the “bridge” class in the place of the reference to the second method.


