Feeling better about the future might help you feel better for real. In a new study, psychological scientists Suzanne Segerstrom of the University of Kentucky and Sandra Sephton of the University of Louisville studied how law students’ expectations about the future affected their immune response. Their conclusions: Optimism may be good for your health.

Other studies found people who are optimistic about their health tend to do better. For example, people who are optimistic about heart transplant surgery recover better from that grueling operation. But it’s not clear how optimism affects your health—or whether pessimism makes you less healthy.

For this study, reported in Psychological Science, a journal of the Association for Psychological Science, the researchers recruited first-year law students by sending them a packet during the summer before classes started. The 124 students that participated in the research were studied at five times over six months. Each time, they answered questions about how optimistic they felt about law school. Then they were injected with material that should summon an immune response and two days later, they came back to have the injection site measured. A larger bump in the skin means a stronger immune response. Immune systems are many-faceted; this test only measures the strength of the part that is responsible for fighting viral infections and some bacterial infections.

The students’ general outlook on life—whether they had an optimistic disposition—didn’t account for the differences in immune responses between students. But as each student’s expectations about law school waxed and waned, their immune response followed along. At more optimistic times, they’d have bigger immune responses; at a more pessimistic time, a more sluggish immune response. So, being optimistic about success in a specific, important domain may promote better immunity against some infections.

Of course, the law students often have good reason to be optimistic or pessimistic; by a few months into the first semester, they’ve gotten some grades back and started to figure out if they’re good or bad at law school. “I don’t think that I would advise people that they should revise their expectations to be unrealistic,” says Segerstrom. “But if people have slightly more positive views of the future than is actually true, that’s adaptive.”