Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

inconsistency between Sun JRE javac and Eclipse java compiler?

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?

like image 605
Jason S Avatar asked Dec 13 '22 22:12

Jason S


1 Answers

This is a known bug in javac - "Inference fails for type variable return constraint":

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954

like image 71
CDSO1 Avatar answered Jan 23 '23 05:01

CDSO1