Java tutorial
//package com.java2s; import android.content.Context; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; public class Main { /** * new a fragment instance * */ @SuppressWarnings("unchecked") public static <T extends Fragment> T newFragment(@NonNull Context context, @NonNull Class<T> clazz, Bundle bundle) { return (T) Fragment.instantiate(context, clazz.getName(), bundle); } }