| Summary: | [Compiler] "Cannot convert from Object to boolean" with Eclipse compiler, but no errors with javac | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Juergen Baier <baier> |
| Component: | Core | Assignee: | Stephan Herrmann <stephan.herrmann> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | stephan.herrmann |
| Version: | 4.14 | ||
| Target Milestone: | 4.15 M3 | ||
| Hardware: | PC | ||
| OS: | Mac OS X | ||
| Whiteboard: | |||
*** This bug has been marked as a duplicate of bug 521939 *** |
Here is a small test program which can be compiled with javac: $ javac --version javac 11.0.5 but prints a compilation error with Eclipse 4.14.0: public class CastToBoolean { public static void main(String[] args) { // TODO Auto-generated method stub Foo foo = new FooImpl(Boolean.TRUE); Boolean value = foo.getAttribute(); if (value) { System.out.println("this works"); } if (foo.getAttribute()) { // <== Eclipse: Type mismatch: Cannot convert from Object to boolean System.out.println("this does NOT work"); } } static interface Foo { <R> R getAttribute(); } static class FooImpl implements Foo { private final Object value; public FooImpl(Object value) { this.value = value; } @SuppressWarnings("unchecked") @Override public <R> R getAttribute() { return (R) value; } } } Expected behavior: The Eclipse compiler should not show an error message.