fragment/src/main/java/androidx/fragment/app/Fragment.java
public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) {
        try {
            Class<?> clazz = sClassMap.get(fname);
            if (clazz == null) {
                // Class not found in the cache, see if it's real, and try to add it
                clazz = context.getClassLoader().loadClass(fname);
                sClassMap.put(fname, clazz);
            }
            Fragment f = (Fragment) clazz.getConstructor().newInstance();
            if (args != null) {
                args.setClassLoader(f.getClass().getClassLoader());
                f.setArguments(args);
            }
            return f;
        } catch (ClassNotFoundException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": make sure class name exists, is public, and has an"
                    + " empty constructor that is public", e);
        } catch (java.lang.InstantiationException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": make sure class name exists, is public, and has an"
                    + " empty constructor that is public", e);
        } catch (IllegalAccessException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": make sure class name exists, is public, and has an"
                    + " empty constructor that is public", e);
        } catch (NoSuchMethodException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": could not find Fragment constructor", e);
        } catch (InvocationTargetException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": calling Fragment constructor caused an exception", e);
        }
    }
/**
     * Create a new instance of a Fragment with the given class name.  This is
     * the same as calling its empty constructor.
     *
     * @param context The calling context being used to instantiate the fragment.
     * This is currently just used to get its ClassLoader.
     * @param fname The class name of the fragment to instantiate.
     * @param args Bundle of arguments to supply to the fragment, which it
     * can retrieve with {@link #getArguments()}.  May be null.
     * @return Returns a new fragment instance.
     * @throws InstantiationException If there is a failure in instantiating
     * the given fragment class.  This is a runtime exception; it is not
     * normally expected to happen.
     */
Create a new instance of a Fragment with the given class name.  This is
the same as calling its empty constructor.

@param context The calling context being used to instantiate the fragment.
This is currently just used to get its ClassLoader.
@param fname The class name of the fragment to instantiate.
@param args Bundle of arguments to supply to the fragment, which it
can retrieve with  #getArguments().  May be null.
@return Returns a new fragment instance.
@throws InstantiationException If there is a failure in instantiating
the given fragment class.  This is a runtime exception; it is not
normally expected to happen.
Create a new instance of a Fragment with the given class name . This is the same as calling its empty constructor . @param context The calling context being used to instantiate the fragment . This is currently just used to get its ClassLoader . @param fname The class name of the fragment to instantiate . @param args Bundle of arguments to supply to the fragment which it can retrieve with #getArguments () . May be null . @return Returns a new fragment instance . @throws InstantiationException If there is a failure in instantiating the given fragment class . This is a runtime exception ; it is not normally expected to happen .
public static Fragment instantiate(Context context, String fname, @Nullable Bundle args) {
        try {
            Class<?> clazz = sClassMap.get(fname);
            if (clazz == null) {
                clazz = context.getClassLoader().loadClass(fname);
                sClassMap.put(fname, clazz);
            }
            Fragment f = (Fragment) clazz.getConstructor().newInstance();
            if (args != null) {
                args.setClassLoader(f.getClass().getClassLoader());
                f.setArguments(args);
            }
            return f;
        } catch (ClassNotFoundException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": make sure class name exists, is public, and has an"
                    + " empty constructor that is public", e);
        } catch (java.lang.InstantiationException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": make sure class name exists, is public, and has an"
                    + " empty constructor that is public", e);
        } catch (IllegalAccessException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": make sure class name exists, is public, and has an"
                    + " empty constructor that is public", e);
        } catch (NoSuchMethodException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": could not find Fragment constructor", e);
        } catch (InvocationTargetException e) {
            throw new InstantiationException("Unable to instantiate fragment " + fname
                    + ": calling Fragment constructor caused an exception", e);
        }
    }
public static Fragment instantiate ( Context context , String fname , @ Nullable Bundle args ) { try { Class < ? > clazz = sClassMap . get ( fname ) ; if ( clazz == null ) { clazz = context . getClassLoader ( ) . loadClass ( fname ) ; sClassMap . put ( fname , clazz ) ; } Fragment f = ( Fragment ) clazz . getConstructor ( ) . newInstance ( ) ; if ( args != null ) { args . setClassLoader ( f . getClass ( ) . getClassLoader ( ) ) ; f . setArguments ( args ) ; } return f ; } catch ( ClassNotFoundException e ) { throw new InstantiationException ( "Unable to instantiate fragment " + fname + ": make sure class name exists, is public, and has an" + " empty constructor that is public" , e ) ; } catch ( java . lang . InstantiationException e ) { throw new InstantiationException ( "Unable to instantiate fragment " + fname + ": make sure class name exists, is public, and has an" + " empty constructor that is public" , e ) ; } catch ( IllegalAccessException e ) { throw new InstantiationException ( "Unable to instantiate fragment " + fname + ": make sure class name exists, is public, and has an" + " empty constructor that is public" , e ) ; } catch ( NoSuchMethodException e ) { throw new InstantiationException ( "Unable to instantiate fragment " + fname + ": could not find Fragment constructor" , e ) ; } catch ( InvocationTargetException e ) { throw new InstantiationException ( "Unable to instantiate fragment " + fname + ": calling Fragment constructor caused an exception" , e ) ; } }
Create a new instance of a Fragment with the given class name.
Create a new instance of a Fragment with the given class name .
// Class not found in the cache, see if it's real, and try to add it