Created
October 5, 2015 12:49
-
-
Save Pr3d4dor/7e722c07edac86a65210 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Exe1MetodosGenericos { | |
public static void print(Gen inputArray){ | |
Object i = inputArray.getob(); | |
for (Integer element : inputArray) | |
System.out.printf("%s ", element); | |
System.out.println(); | |
} | |
// método printArray para imprimir o array Integer | |
public static void printArray(Integer[] inputArray) { | |
// exibe elementos do array | |
for (Integer element : inputArray) | |
System.out.printf("%s ", element); | |
System.out.println(); | |
} | |
// método printArray para imprimir o array Double | |
public static void printArray(Double[] inputArray) { | |
// exibe elementos do array | |
for (Double element : inputArray) | |
System.out.printf("%s ", element); | |
System.out.println(); | |
} | |
// método printArray para imprimir um array Character | |
public static void printArray(Character[] inputArray) { | |
// exibe elementos do array | |
for (Character element : inputArray) | |
System.out.printf("%s ", element); | |
System.out.println(); | |
} | |
public static void main(String args[]) { | |
// cria arrays do Integer, Double e Character | |
Gen<Integer> ob1; | |
Gen<Double> ob2; | |
Gen<Character> ob3; | |
Integer[] integerArray = { 1, 2, 3, 4, 5, 6 }; | |
Double[] doubleArray = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 }; | |
Character[] characterArray = { 'B', 'O', 'M',' ','D','I', 'A','!'}; | |
ob1 = new Gen<Integer>(integerArray); | |
ob2 = new Gen<Double>(doubleArray); | |
ob3 = new Gen<Character>(characterArray); | |
System.out.println("Array integerArray contém:"); | |
print(ob1); // passa um array Integer | |
System.out.println("\nArray doubleArray contém:"); | |
//print(ob2); // passa um array Double | |
System.out.println("\nArray characterArray contém:"); | |
//print(ob3); // passa um array Character | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment