Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 100

Given TripleThis.java:

Compiling TripleThis.java gives this compiler warning:

Note: TripleThis.java uses unchecked or unsafe operations.

Which two replacements remove this compiler warning and prints 12? (Choose two.)

    Correct Answer: A, D

    To remove the compiler warning and print 12, we need to address two main issues: the unchecked operation due to the raw type usage and the generic type usage for the integer. Replacing line 12 with the method signature 'public static void printValue(Function f, int num)' resolves the generic type issue by specifying an 'int' type for the method parameter 'num'. Additionally, replacing the same method signature with 'public static void printValue(Function f, Integer num)' ensures type safety for the num parameter as an 'Integer'. This explicitly defines the type expected and used, which aligns with the tripler function's return type, thereby resolving the unchecked warning and achieving the correct output.

Discussion
dillemanOptions: AD

Tested, A and D

StavokOptions: AD

A & D are correct

ASPushkin

This code doesn't compiled "T is not found" it will compile if written something like this public static <T extends Integer> void printValue(Function f, T num) { There is no correct answer This code, for example, remove the compile warning : public static void main(String[] args) { Function <Integer, Integer> triple = x -> { return x*3; }; MyClass.printValue(triple, 4); } public static void printValue(Function<Integer, Integer> f, int num) { System.out.println(f.apply(num)); }