work/workmanager/src/main/java/androidx/work/impl/WorkerWrapper.java
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    @SuppressWarnings("ClassNewInstance")
    public static Worker workerFromClassName(
            @NonNull Context context,
            @NonNull String workerClassName,
            @NonNull UUID workSpecId,
            @NonNull Extras extras) {
        Context appContext = context.getApplicationContext();
        try {
            Class<?> clazz = Class.forName(workerClassName);
            Worker worker = (Worker) clazz.newInstance();
            Method internalInitMethod = Worker.class.getDeclaredMethod(
                    "internalInit",
                    Context.class,
                    UUID.class,
                    Extras.class);
            internalInitMethod.setAccessible(true);
            internalInitMethod.invoke(
                    worker,
                    appContext,
                    workSpecId,
                    extras);
            return worker;
        } catch (Exception e) {
            Log.e(TAG, "Trouble instantiating " + workerClassName, e);
        }
        return null;
    }
/**
     * Creates a {@link Worker} reflectively & initializes the worker.
     *
     * @param context         The application {@link Context}
     * @param workerClassName The fully qualified class name for the {@link Worker}
     * @param workSpecId      The {@link WorkSpec} identifier
     * @param extras          The {@link Extras} for the worker
     * @return The instance of {@link Worker}
     *
     * @hide
     */
Creates a  Worker reflectively & initializes the worker.

@hide
Creates a Worker reflectively & initializes the worker . @hide
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
    @SuppressWarnings("ClassNewInstance")
    public static Worker workerFromClassName(
            @NonNull Context context,
            @NonNull String workerClassName,
            @NonNull UUID workSpecId,
            @NonNull Extras extras) {
        Context appContext = context.getApplicationContext();
        try {
            Class<?> clazz = Class.forName(workerClassName);
            Worker worker = (Worker) clazz.newInstance();
            Method internalInitMethod = Worker.class.getDeclaredMethod(
                    "internalInit",
                    Context.class,
                    UUID.class,
                    Extras.class);
            internalInitMethod.setAccessible(true);
            internalInitMethod.invoke(
                    worker,
                    appContext,
                    workSpecId,
                    extras);
            return worker;
        } catch (Exception e) {
            Log.e(TAG, "Trouble instantiating " + workerClassName, e);
        }
        return null;
    }
@ RestrictTo ( RestrictTo . Scope . LIBRARY_GROUP ) @ SuppressWarnings ( "ClassNewInstance" ) public static Worker workerFromClassName ( @ NonNull Context context , @ NonNull String workerClassName , @ NonNull UUID workSpecId , @ NonNull Extras extras ) { Context appContext = context . getApplicationContext ( ) ; try { Class < ? > clazz = Class . forName ( workerClassName ) ; Worker worker = ( Worker ) clazz . newInstance ( ) ; Method internalInitMethod = Worker . class . getDeclaredMethod ( "internalInit" , Context . class , UUID . class , Extras . class ) ; internalInitMethod . setAccessible ( true ) ; internalInitMethod . invoke ( worker , appContext , workSpecId , extras ) ; return worker ; } catch ( Exception e ) { Log . e ( TAG , "Trouble instantiating " + workerClassName , e ) ; } return null ; }
Creates a {@link Worker} reflectively & initializes the worker.
Creates a { @link Worker } reflectively & initializes the worker .