Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8224720

Error in test example of Java certified programmer guide

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      https://www.oracle.com/a/ocom/img/dc/ww-java11-programmer-study-guide.pdf

      The correct answer for the 5th question is B(not C as written at the bottom of the page)
      When choosing the overridden method to execute the widening of the primitive argument comes before autoboxing. Byte arguments will be widened to long first and the method "void doCalc(long a, long b)" will be invoked.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run
      public class Client {
       static void doCalc(byte... a) {
       System.out.print("byte...");
       }
       static void doCalc(long a, long b) {
       System.out.print("long, long");
       }
       static void doCalc(Byte s1, Byte s2) {
       System.out.print("Byte, Byte");
       }
       public static void main (String[] args) {
       Byte b = 5;
       doCalc(b, b);
       }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Byte, Byte
      ACTUAL -
      long, long

        Attachments

          Activity

            People

            • Assignee:
              fmatte Fairoz Matte
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: