-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
None
-
generic
-
generic
(1) The following program does not compile:
public class X {
public static void main(String args[]) {
Object o = null;
if (o __matches (42 + 0)) {
}
}
}
/home/srikanth/tmp/X.java:5: error: ')' expected
if (o __matches (42 + 0)) {
^
/home/srikanth/tmp/X.java:5: error: ';' expected
if (o __matches (42 + 0)) {
^
2 errors
(2) The following program is expected to compile but fail at runtime with Arithmetic exception, but fails to compile:
public class X {
public static void main(String args[]) {
Object o = null;
if (o __matches 42 / 0) {
}
}
}
Javac message:
/home/srikanth/tmp/X.java:5: error: constant expression required
if (o __matches 42 / 0) {
^
1 error
(Compare with int x = 42/0; which fails with Arithmetic exception)
(3) This program shows some odd behavior:
public class X {
public static void main(String args[]) {
Object o = null;
if (o __matches String x __matches true) {} // This compiles
if (o __matches true __matches false) {} // This does not - Why ?
}
}
compiler's complaint being:
/home/srikanth/tmp/X.java:6: error: constant expression required
if (o __matches true __matches false) {} // This does not - Why ?
^
1 error
public class X {
public static void main(String args[]) {
Object o = null;
if (o __matches (42 + 0)) {
}
}
}
/home/srikanth/tmp/X.java:5: error: ')' expected
if (o __matches (42 + 0)) {
^
/home/srikanth/tmp/X.java:5: error: ';' expected
if (o __matches (42 + 0)) {
^
2 errors
(2) The following program is expected to compile but fail at runtime with Arithmetic exception, but fails to compile:
public class X {
public static void main(String args[]) {
Object o = null;
if (o __matches 42 / 0) {
}
}
}
Javac message:
/home/srikanth/tmp/X.java:5: error: constant expression required
if (o __matches 42 / 0) {
^
1 error
(Compare with int x = 42/0; which fails with Arithmetic exception)
(3) This program shows some odd behavior:
public class X {
public static void main(String args[]) {
Object o = null;
if (o __matches String x __matches true) {} // This compiles
if (o __matches true __matches false) {} // This does not - Why ?
}
}
compiler's complaint being:
/home/srikanth/tmp/X.java:6: error: constant expression required
if (o __matches true __matches false) {} // This does not - Why ?
^
1 error