Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.lang.reflect.Array;

public class Main {
    /**
     * Makes an array based on klass, but casts it to be of type T[]. This is a very
     * unsafe operation and should be used carefully. Namely, you should ensure that
     * klass is a subtype of T, or that klass is a supertype of T *and* that the array
     * will not escape the generic constant *and* that klass is the same as the erasure
     * of T.
     * @param <T>
     */
    @SuppressWarnings("unchecked")
    public static <T> T[] mkTArray(Class<?> klass, int size) {
        return (T[]) (Array.newInstance(klass, size));

    }
}