aspose file tools
The moose likes Java in General and the fly likes ThreadLocal Type Safety Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "ThreadLocal Type Safety "Generics"" Watch "ThreadLocal Type Safety "Generics"" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ThreadLocal Type Safety "Generics"
 
Similar Threads
Generics
Generics..
Generics
Generics