From 86e887285c3a2f92818fb0dfa6484fbc25fd6797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Guzm=C3=A1n?= Date: Wed, 8 Jul 2026 17:04:02 -0500 Subject: [PATCH] Refactor Printer class to use generics Completed solution with Generic Method Declaration, Type Safety, Single Method and Type Inference --- Java/Collections/JavaGenerics.java | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Java/Collections/JavaGenerics.java b/Java/Collections/JavaGenerics.java index 5664459..df47d89 100644 --- a/Java/Collections/JavaGenerics.java +++ b/Java/Collections/JavaGenerics.java @@ -17,13 +17,26 @@ */ -class Printer -{ - public static void printArray(Object[] arr) - { - for(int i = 0;i void printArray(T[] array) { + for (T element : array) { + System.out.println(element); } + } + + public static void main(String[] args) { + + + Integer[] intArray = {1, 2, 3}; + + String[] stringArray = {"Hello", "World"}; + + printArray(intArray); + printArray(stringArray); } -} \ No newline at end of file +}