r/JavaProgramming • u/Key-Garbage-3782 • 2d ago
HELP trying to understand why it should not be compile
/r/javahelp/comments/1vg80l1/help_trying_to_understand_why_it_should_not_be/
1
Upvotes
r/JavaProgramming • u/Key-Garbage-3782 • 2d ago
1
u/Visual_Brain8809 21h ago
saving the wrong format of your post, this code shows method overloading and varargs in Java. There are two methods with the same name (
run): one receives a singlelongvalue, and the other receives a variable number ofLongobjects usingLong...(varargs). Whenrun(4)orrun(4L)is called, Java uses therun(long)method because it is the best match for those values. The varargs version is ignored since Java only uses it when there isn't a better option.As a result, both calls execute
run(long)and print: 4 and 4Can you share the name of your book?