Name: ddT132432 Date: 01/09/2002
FULL PRODUCT VERSION :
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
A DESCRIPTION OF THE PROBLEM :
Trying to compile the attached snippet gives the error
message included farther down, a rather puzzling one.
Jikes does better here; it puts:
*** Error: In this conditional expression, the type of the
false subexpression, "Bug1$2", is not compatible with the
type of the true subexpression, "Bug1$1".
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the class below.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Bug1.java:6: incompatible types
found : <anonymous java.awt.event.ActionListener>
required: <anonymous java.awt.event.ActionListener>
ActionListener l = (true) ?
^
1 error
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.event.*;
public class Bug1 {
public static final void main(String[] argv) {
ActionListener l = (true) ? new ActionListener() {
public void actionPerformed(ActionEvent evt) { } } :
new ActionListener() {public void actionPerformed(ActionEvent evt) { } };
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Explicitely cast both anonymous classes to ActionListener.
This may or may not be correct behaviour as per the
JLS but it is daft and does not make for readable code.
(Review ID: 138044)
======================================================================