- 3,709,609 Users
- 2,241,337 Discussions
- 7,841,258 Comments
Forum Stats
Discussions
Categories
- 9 Data
- 362.2K Big Data Appliance
- 3 Data Science
- 1.1K Databases
- 346 General Database Discussions
- 3.7K Java and JavaScript in the Database
- 22 Multilingual Engine
- 480 MySQL Community Space
- 3 NoSQL Database
- 7.6K Oracle Database Express Edition (XE)
- 2.7K ORDS, SODA & JSON in the Database
- 411 SQLcl
- 33 SQL Developer Data Modeler
- 184.7K SQL & PL/SQL
- 20.9K SQL Developer
- 1.4K Development
- 1 Developer Projects
- 31 Programming Languages
- 134.6K Development Tools
- 4 DevOps
- 3K QA/Testing
- 176 Java
- 3 Java Learning Subscription
- 7 Database Connectivity
- 64 Java Community Process
- Java 25
- 7 Java APIs
- 141.1K Java Development Tools
- 2 Java EE (Java Enterprise Edition)
- 153K Java Essentials
- 132 Java 8 Questions
- 86.1K Java Programming
- 270 Java Lambda MOOC
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 6 Java SE
- 13.8K Java Security
- 3 Java User Groups
- 22 JavaScript - Nashorn
- 18 Programs
- 83 LiveLabs
- 23 Workshops
- 7 Software
- 3 Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 3 Deutsche Oracle Community
- 6 Español
- 1.9K Japanese
- 2 Portuguese
Autoboxing int Integer

Hi,
I am preparing for the exam.
I need help to understand why in this code the int method is chosen, I have tested only with Integer and that one is also executed:
public class Teststuff {
public static void doSum(Integer x, Integer y){
System.out.println("Integer sum is "+(x+y));
}
public static void doSum(int x, int y){
System.out.println("int sum is "+(x+y));
}
public static void main(String[] args) {
doSum(10, 20);
}
}
Thank you!
Answers
Just try to reason which method would be the closest match, and the answer becomes quite obvious.
There is of course a potential for ambiguity, and that's if you try to call for example doSum(10, Integer.valueOf(20));
I've not tried what would happen in that case, I'd not be surprised if it'd lead to a compiler error.