Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.List;

public class Main {
    public static <T> void fill(List<T> list, int start, int end, Class<T> clazz) {
        for (int i = start; i <= end; i++) {
            try {

                list.set(i, clazz != null ? clazz.newInstance() : null);

            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static <T> void fill(T[] list, int start, int end, Class<T> clazz) {
        for (int i = start; i <= end; i++) {
            try {
                list[i] = clazz != null ? clazz.newInstance() : null;
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }
}