Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { Job job = ctx.getBean(bundle.getJobDetail().getJobClass()); }
上面的代码在没有类型转换的情况下不起作用..为什么当 getBean 的输入类型是 Class < T > 并且返回类型是 T 时需要类型转换
在运行时之前,JVM 可能无法从您的代码中分辨出 bean 的类型,因此无法编译它。您要么必须在此处向下转换,要么更改getJobClass()方法的签名(以 return Class<? extends Job>)。
getJobClass()
Class<? extends Job>