Class<? extends SendDataJob> clszz 这个参数怎么理解?反射类还是什么?

public void starSendDataJob(Class<? extends SendDataJob> clszz,int intervalMin,String topcic){
        try {
            JobDetail senddatajobDetail = JobBuilder.newJob(clszz)
                    .withIdentity(new JobKey(clszz.getSimpleName(), collectorJobGroup)).storeDurably().build();
            senddatajobDetail.getJobDataMap().put("topic", topcic);
            scheduler.addJob(senddatajobDetail, true);
            addTrigger(clszz.getSimpleName(),senddatajobDetail, intervalMin);
        } catch (SchedulerException e) {
            log.error("start send data job error,jobname:{}",clszz.getName());
            log.error("start send data job error",e);
            e.printStackTrace();
        }
    }
阅读 4.3k
4 个回答

还能怎么理解呢,就是表示在运行时表示这个对象的类。
Java万物基于Object。
请看Object里面的getClass方法。

/**
     * Returns the runtime class of this {@code Object}. The returned
     * {@code Class} object is the object that is locked by {@code
     * static synchronized} methods of the represented class.
     *
     * <p><b>The actual result type is {@code Class<? extends |X|>}
     * where {@code |X|} is the erasure of the static type of the
     * expression on which {@code getClass} is called.</b> For
     * example, no cast is required in this code fragment:</p>
     *
     * <p>
     * {@code Number n = 0;                             }<br>
     * {@code Class<? extends Number> c = n.getClass(); }
     * </p>
     *
     * @return The {@code Class} object that represents the runtime
     *         class of this object.
     * @jls 15.8.2 Class Literals
     */
    public final native Class<?> getClass();

首先,我假定你是知道泛型这个概念,如果不知道泛型你可以去看Oracle Java对泛型的描述

这个的参数是Class类型但是传递进来的Class的类型必须是继承SendDataJob这个类的类型

知识点:泛型,字节码,反射

Class对象,就是类的元信息对象,保存一个类的字段,方法等等元信息。
<? extends SendDataJob> 泛型,说明clazz对象是SendDataJob子类的类对象。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题