Files
HackerRank-Solutions/Java/Data Structures/Java Generics/Solution.java
T

37 lines
960 B
Java
Raw Normal View History

2017-02-18 23:43:07 -06:00
// Author: Rodney Shaghoulian
// Github: github.com/rshaghoulian
// HackerRank: hackerrank.com/rshaghoulian
import java.io.IOException;
import java.lang.reflect.Method;
2017-02-21 00:05:09 -06:00
class Printer {
public <T> void printArray(T[] array) {
2017-02-18 23:43:07 -06:00
for (T item : array) {
System.out.println(item);
}
}
}
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();
2017-02-24 00:24:47 -06:00
if (name.equals("printArray")) {
2017-02-18 23:43:07 -06:00
count++;
2017-02-24 00:24:47 -06:00
}
2017-02-18 23:43:07 -06:00
}
2017-02-24 00:24:47 -06:00
if (count > 1) {
System.out.println("Method overloading is not allowed!");
}
2017-02-18 23:43:07 -06:00
}
}