java - JDK7 Compilation Error: Ambiguity reference -


i trying migrate legacy code base java1.6 1.7 , getting following error while compiling:

reference create ambiguous, both method create(long,object...) in meta , method create(object...) in meta match

here meta class name. error seen when compiling jdk1.7. in 1.6 building fine , dependencies working fine well.

the 2 polymorphic functions follows :

 create(long id, object... paramters) {     ....  }  create(object... paramters) {    .... } 

how resolve code works both 1.6 compilation , 1.7 compilation.

edit : adding call examples throwing error:

id.create(1234); id.create(id); // id long value 

this caused fix in java 7 compiler:

incompatibilities between jdk 7 , jdk 6

area: tools

synopsis: changes in specific varargs method selection

description: overload resolution algorithm in javac compiler has been fixed in how selects specific varargs method when more 1 method applicable given call-site (see jls, java se 7 edition, section 15.12.2.5).

...

while javac compiler accepts more code did prior jdk 7, fix results in slight source incompatibility in following case:

class test {     void foo(int... i) {}     void foo(object... o) {}      void test() {        foo(1,2,3);     } } 

this code compiles in jdk 6 (the specific method foo(int...)). code not compile under jdk 7.


to make code work in both jdks, need give compiler additional hint select proper method, example like

id.create(1234, new object[0]); id.create(id, new object[0]); 

this call create(long id, object... parameters) both jdk6 , jdk7, , pass array of size 0 varargs part passed in case of java 6 original code.

nevertheless, looks bit weird, , choose (for better readability) rename 1 of methods, method invocation not rely on signature.

you should consider java6 in end-of-life cycle, option modify code compilable java7 in first place.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -