HR자바 Java Generics

개요[ | ]

HR자바 Java Generics
해커랭크 Java
# 문제 비고
HR자바 Data Structures e
28 HR자바 Java 1D Array
29 HR자바 Java 2D Array
30 HR자바 Java Subarray
31 HR자바 Java Arraylist
32 HR자바 Java 1D Array (Part 2)
33 HR자바 Java List
34 HR자바 Java Map
35 HR자바 Java Stack
36 HR자바 Java Hashset
37 HR자바 Java Generics
38 HR자바 Java Comparator
39 HR자바 Java Sort
40 HR자바 Java Dequeue
41 HR자바 Java BitSet
42 HR자바 Java Priority Queue

import java.io.IOException;
import java.lang.reflect.Method;
class Printer
{
   //Write your code here
    public static <E> void printArray(E[] arr) {
        for( E el: arr ) {
            System.out.println(el);
        }
    }
}
public class Solution {

    public static void main( String args[] ) {
        Printer myPrinter = new Printer();
        Integer[] intArray = { 1, 2, 3 };
        String[] stringArray = {"Hello", "World"};
        myPrinter.printArray(intArray);
        myPrinter.printArray(stringArray);
        int count = 0;

        for (Method method : Printer.class.getDeclaredMethods()) {
            String name = method.getName();
            if(name.equals("printArray"))
                count++;
        }
        if(count > 1)System.out.println("Method overloading is not allowed!");
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}