inconsistency between Sun JRE javac and Eclipse java compiler?

Posted by Jason S on Stack Overflow See other posts from Stack Overflow or by Jason S
Published on 2010-04-14T18:39:04Z Indexed on 2010/04/14 18:53 UTC
Read the original article Hit count: 221

Filed under:
|
|

This confuses me. The following compiles fine under Eclipse.

package com.example.gotchas;

public class GenericHelper1 {

 static <T> T fail() throws UnsupportedOperationException
 {
  throw new UnsupportedOperationException();
 } 

 /**
  * just calls fail()
  * @return something maybe
  */
 public boolean argh() { return fail(); }

 public static void main(String[] args) {
  // TODO Auto-generated method stub

 }

}

But if I try to do a clean build with ant, or at the command line with javac, I get this:

src\com\example\gotchas\GenericHelper1.java:14: type parameters of <T>T cannot be determined; no unique maximal instance
 exists for type variable T with upper bounds boolean,java.lang.Object
        public boolean argh() { return fail(); }
                                           ^
1 error

what gives, and how do I fix it?

© Stack Overflow or respective owner

Related posts about java

Related posts about compiler-errors