IT-Academy icon

Genericke metódy

IT-Academy | PRO | 10/31/17 12:07:08 PM UTC | 0 ⭐ | 579 👁️ | Never ⏰ | []
Java |

940 B

|

None

|

0 👍

/

0 👎

 
public class GenerickeMetody {
 
    public static void main(String[] args) {
        Integer[] poleObjCisla = {4, 8, 2, 3};
        Character[] poleObjZnaky = {'a', 'x', 'c'};
        String[] poleStringov = {"Karol","Eva","Nina"};
        
        
        
        vytlacPole(poleObjCisla);
        vytlacPole(poleObjZnaky);
        vytlacPole(poleStringov);
    }
    
    public static <T> void vytlacPole(T[] pole){
        for (T t : pole) {
            System.out.print(t);
        }
        System.out.println("");
    }
 
//    private static void vytlacPole(Integer[] poleObjCisla) {
//        for (Integer i : poleObjCisla) {
//            System.out.print(i);
//        }
//        System.out.println("");
//    }
//
//    private static void vytlacPole(Character[] poleObjZnaky) {
//        for (Character x : poleObjZnaky) {
//            System.out.print(x);
//        }
//        System.out.println("");
//    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎