| Author |
ThreadLocal Type Safety "Generics"
|
Thomas Bigbee
Ranch Hand
Joined: Nov 29, 2001
Posts: 48
|
|
I've run across this warning, and I'm trying to figure out a way to correct it, I've tried to fix it using generics, however, I have not been able to make the warning go away. Any feedback would be appreciated Type safety: The method set(Object) belongs to the raw type ThreadLocal. References to generic type ThreadLocal<T> should be parameterized public static final ThreadLocal session = new ThreadLocal(); public static Session currentSession() throws HibernateException { Session s = (Session) session.get(); // Open a new Session, if this Thread has none yet if (s == null) { s = sessionFactory.openSession(); session.set(s); } return s; }
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
|
What does your version using generics look like?
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Have you tried:
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Thomas Bigbee
Ranch Hand
Joined: Nov 29, 2001
Posts: 48
|
|
|
Thanks Berry, that did the trick
|
 |
 |
|
|
subject: ThreadLocal Type Safety "Generics"
|
|
|