code_junkie

Why does autoboxing make some calls ambiguous in Java

Nov 14th, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public class Test {
  2. static void f(Object a, boolean b) {}
  3. static void f(Object a, Object b) {}
  4.  
  5. static void m(int a, boolean b) { f(a,b); }
  6. }
  7.  
  8. Test.java:5: reference to f is ambiguous, both method
  9. f(java.lang.Object,boolean) in Test and method
  10. f(java.lang.Object,java.lang.Object) in Test match
  11.  
  12. static void m(int a, boolean b) { f(a, b); }
  13. ^
  14.  
  15. static void m(int a, boolean b) { f((Object)a, b); }
  16.  
  17. public class Test {
  18. static void f(Object a, boolean b) {}
  19. static void f(int a, Object b) {}
  20.  
  21. static void m(int a, boolean b) { f(a, b); } // ambiguous
  22. }
  23.  
  24. f(boolean a, Object b)
  25. f(Object a , boolean b)
Add Comment
Please, Sign In to add comment