package net.sf.hibernate.examples.quickstart;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
◎SuppressWarnings("Unchecked")
public class HibernateUtil{
private static Log log=LogFactory.getLog(HibernateUtil.class); private static final SessionFactory sessionFactory;
static{
try{
sessionFactory=new Configuration().configure().buildSessionFactory();
}
catch(Throwable ex){
log.error("Initial SessionFactory creation failed.",ex);
throw new ExceptionInInitializerError(ex);
}
}
public static final ThreadLocal session=new ThreadLocal();
◎SuppressWarnings("Unchecked")
public static Session currentSession() throws HibernateException{
Session s=(Session)session.get();
if(s==null){
s=sessionFactory.openSession();
session.set(s);
}
return s;
}
◎SuppressWarnings("Unchecked")
public static void closeSession() throws HibernateException{
Session s=(Session)session.get();
session.set(null);
if(s!=null)
s.close();
}
}
我用了◎SuppressWarnings("Unchecked")这个啊 为什么编译器还报
"使用了未经检查或不安全的操作"
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
◎SuppressWarnings("Unchecked")
public class HibernateUtil{
private static Log log=LogFactory.getLog(HibernateUtil.class); private static final SessionFactory sessionFactory;
static{
try{
sessionFactory=new Configuration().configure().buildSessionFactory();
}
catch(Throwable ex){
log.error("Initial SessionFactory creation failed.",ex);
throw new ExceptionInInitializerError(ex);
}
}
public static final ThreadLocal session=new ThreadLocal();
◎SuppressWarnings("Unchecked")
public static Session currentSession() throws HibernateException{
Session s=(Session)session.get();
if(s==null){
s=sessionFactory.openSession();
session.set(s);
}
return s;
}
◎SuppressWarnings("Unchecked")
public static void closeSession() throws HibernateException{
Session s=(Session)session.get();
session.set(null);
if(s!=null)
s.close();
}
}
我用了◎SuppressWarnings("Unchecked")这个啊 为什么编译器还报
"使用了未经检查或不安全的操作"
@SuppressWarnings(value={"unchecked", "deprecation"})
当你的编码可能存在警告时,比如安全警告,可以用它来消除 api中是这样描述的
指示应该在注释元素(以及包含在该注释元素中的所有程序元素)中取消显示指定的编译器警告。注意,在给定元素中取消显示的警告集是所有包含元素中取消显示的警告的超集。例如,如果注释一个类来取消显示某个警告,同时注释一个方法来取消显示另一个警告,那么将在此方法中同时取消显示这两个警告。 根据风格不同,程序员应该始终在最里层的嵌套元素上使用此注释,在那里使用才有效。如果要在特定的方法中取消显示某个警告,则应该注释该方法而不是注释它的类。